Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Used date-fns to autofill IEP end date and correctly format IEP dates in student_id #225

Merged
merged 5 commits into from
Oct 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/pages/students/[student_id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ import $Form from "../../styles/Form.module.css";
import $Modal from "../../styles/Modal.module.css";
import $StudentPage from "../../styles/StudentPage.module.css";
import $Image from "../../styles/Image.module.css";
import { parseISO, addYears, subDays, format } from "date-fns";

const ViewStudentPage = () => {
const [createIepModal, setCreateIepModal] = useState(false);
const [archivePrompt, setArchivePrompt] = useState(false);
const [startDate, setStartDate] = useState("");
const [endDate, setEndDate] = useState("");

const utils = trpc.useContext();
const router = useRouter();
Expand Down Expand Up @@ -48,6 +51,16 @@ const ViewStudentPage = () => {
onSuccess: () => utils.student.getActiveStudentIep.invalidate(),
});

const handleAutofillIepEndDate = (date: string) => {
//new IEP generally starts on same date annually, so end date autofills to the day before one year from start date
setStartDate(date);
const parsedDate: Date = parseISO(date);
const datePlusOneYear: Date = addYears(parsedDate, 1);
const finalDate: Date = subDays(datePlusOneYear, 1);
const formattedEndDate: string = format(finalDate, "yyyy-MM-dd");
setEndDate(formattedEndDate);
};

const handleIepSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
const data = new FormData(event.currentTarget);
Expand All @@ -57,8 +70,8 @@ const ViewStudentPage = () => {
}
iepMutation.mutate({
student_id: student.student_id,
start_date: new Date(data.get("start_date") as string),
end_date: new Date(data.get("end_date") as string),
start_date: new Date(parseISO(data.get("start_date") as string)),
end_date: new Date(parseISO(data.get("end_date") as string)),
});

setCreateIepModal(false);
Expand Down Expand Up @@ -195,6 +208,10 @@ const ViewStudentPage = () => {
type="date"
name="start_date"
placeholder="IEP start date"
value={startDate}
onChange={(e) => {
handleAutofillIepEndDate(e.target.value);
}}
required
/>
</Box>
Expand All @@ -204,6 +221,7 @@ const ViewStudentPage = () => {
type="date"
name="end_date"
placeholder="IEP end date"
value={endDate}
required
/>
</Box>
Expand Down
Loading