From a948554e494ec0f2e68e900c0fa6acfc746814ef Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Sat, 3 Feb 2024 23:36:07 -0500 Subject: [PATCH 1/3] set and get due date --- src/services/housing.ts | 5 +++++ src/views/HousingLottery/adminView/index.jsx | 20 +++++++++++++++++++ .../HousingLottery/studentView/index.jsx | 15 ++++++++++++-- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/services/housing.ts b/src/services/housing.ts index 5f9d7da7e4..daa1d40fbf 100644 --- a/src/services/housing.ts +++ b/src/services/housing.ts @@ -70,6 +70,7 @@ const getAllApplicant = (): Promise => http.get('housing/housing_lottery/all_applicant'); const getAllSchoolYear = (): Promise => http.get('housing/housing_lottery/all_school_year'); +const getDueDate = (): Promise => http.get('housing/housing_lottery/get_due_date'); const getCurrentApplicationID = (username: string = ''): Promise => http.get(username ? `housing/apartment/${username}/` : 'housing/apartment/'); @@ -182,6 +183,8 @@ const addHall = (applicantion_id: string, hallList: string[]) => const addPreference = (applicantion_id: string, preferenceList: string[]) => http.put(`housing/housing_lottery/preference/${applicantion_id}`, preferenceList); +const addDueDate = (dueDate: string) => http.put(`housing/housing_lottery/due_date/`, dueDate); + const housingService = { getApartmentSelectionDate, getApartmentHalls, @@ -190,6 +193,7 @@ const housingService = { getAllPreferredHall, getAllApplicant, getAllSchoolYear, + getDueDate, getCurrentApplicationID, saveApartmentApplication, deleteApartmentApplication, @@ -200,6 +204,7 @@ const housingService = { addApplicant, addHall, addPreference, + addDueDate, }; export default housingService; diff --git a/src/views/HousingLottery/adminView/index.jsx b/src/views/HousingLottery/adminView/index.jsx index 91c0b8da90..322f02e609 100644 --- a/src/views/HousingLottery/adminView/index.jsx +++ b/src/views/HousingLottery/adminView/index.jsx @@ -13,6 +13,7 @@ import { Card, CardHeader, CardContent, + TextField, Link, } from '@mui/material'; import housingService from 'services/housing'; @@ -26,12 +27,14 @@ const AdminView = () => { const [preferredHall, setPreferredHall] = useState([]); const [applicant, setApplicant] = useState([]); const [schoolYear, setSchoolYear] = useState([]); + const [dueDate, setDueDate] = useState(''); useEffect(() => { housingService.getAllPreference().then(setPreference); housingService.getAllPreferredHall().then(setPreferredHall); housingService.getAllApplicant().then(setApplicant); housingService.getAllSchoolYear().then(setSchoolYear); + housingService.getDueDate().then(setDueDate); }, []); const csvData = data.map((row) => ({ @@ -75,9 +78,26 @@ const AdminView = () => { console.log(schoolYear); }; + const submitDueDate = async () => { + await housingService.addDueDate(dueDate); + }; + return ( + + setDueDate(event.target.value)} + /> + + diff --git a/src/views/HousingLottery/studentView/index.jsx b/src/views/HousingLottery/studentView/index.jsx index 904ca89df1..c3280035b9 100644 --- a/src/views/HousingLottery/studentView/index.jsx +++ b/src/views/HousingLottery/studentView/index.jsx @@ -19,15 +19,20 @@ const StudentView = () => { setEmail(profile.Email); setStudentApplicantResult([email]); }, [email]); + const [preferredHallResult, setPreferredHallResult] = useState([]); const [preferenceResult, setPreferenceResult] = useState([]); - const application_id = nanoid(8); const [snackbar, setSnackbar] = useState({ message: '', severity: null, open: false }); const [areAllAgreementsChecked, setAreAllAgreementsChecked] = useState(false); console.log('Preferred Hall Result:', preferredHallResult); console.log('Student Applicant Result:', studentApplicantResult); console.log('Preference Result:', preferenceResult); + const [dueDate, setDueDate] = useState(''); + useEffect(() => { + housingService.getDueDate().then(setDueDate); + }, []); + const handleAgreementsChange = (allChecked) => { const agreementData = [allChecked]; console.log('Agreement Data:', agreementData); @@ -41,7 +46,13 @@ const StudentView = () => { const handleClick = async () => { try { - console.log(application_id); + let application_id = nanoid(8), + timeTarget = new Date(dueDate + ' 11:24:00 PM').getTime(), + timeNow = new Date().getTime(); + if (timeNow > timeTarget) { + application_id = 'zzz' + timeNow; + } + console.log('application_id ' + application_id); await housingService.addApplicant(application_id, studentApplicantResult); await housingService.addHall(application_id, preferredHallResult); await housingService.addPreference(application_id, preferenceResult); From a4faf0bf3fd94ee31b267a93201ccbd8679680d5 Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 5 Feb 2024 01:56:19 -0500 Subject: [PATCH 2/3] Fixed date input formatting --- src/views/HousingLottery/adminView/index.jsx | 25 ++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/views/HousingLottery/adminView/index.jsx b/src/views/HousingLottery/adminView/index.jsx index 322f02e609..8ce21de3b6 100644 --- a/src/views/HousingLottery/adminView/index.jsx +++ b/src/views/HousingLottery/adminView/index.jsx @@ -19,6 +19,7 @@ import { import housingService from 'services/housing'; import styles from '../HousingLottery.module.css'; import { CSVLink } from 'react-csv'; +import { setDate } from 'date-fns'; const AdminView = () => { const [data, setData] = useState([]); @@ -77,6 +78,20 @@ const AdminView = () => { console.log(applicant); console.log(schoolYear); }; + + const handleDateChange = (event) => { + let input = event.target.value.replace(/\D/g, ''); + + if (/^\d+$/.test(input)) { + if (input.length <= 2) { + setDueDate(input); + } else if (input.length <= 4) { + setDueDate(`${input.slice(0, 2)}/${input.slice(2)}`); + } else { + setDueDate(`${input.slice(0, 2)}/${input.slice(2, 4)}/${input.slice(4, 8)}`); + } + } + }; const submitDueDate = async () => { await housingService.addDueDate(dueDate); @@ -92,9 +107,15 @@ const AdminView = () => { color="secondary" label="Due Date" value={dueDate} - onChange={(event) => setDueDate(event.target.value)} + onChange={handleDateChange} + margin="normal" + helperText="* MM/DD/YYYY" /> - From 573a4549ef71d85d8b84639ec03661363fc609e3 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Thu, 8 Feb 2024 20:10:39 -0500 Subject: [PATCH 3/3] update time for due date --- src/views/HousingLottery/studentView/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/HousingLottery/studentView/index.jsx b/src/views/HousingLottery/studentView/index.jsx index c3280035b9..59622c4bf1 100644 --- a/src/views/HousingLottery/studentView/index.jsx +++ b/src/views/HousingLottery/studentView/index.jsx @@ -47,7 +47,7 @@ const StudentView = () => { const handleClick = async () => { try { let application_id = nanoid(8), - timeTarget = new Date(dueDate + ' 11:24:00 PM').getTime(), + timeTarget = new Date(dueDate + ' 11:59:59 PM').getTime(), timeNow = new Date().getTime(); if (timeNow > timeTarget) { application_id = 'zzz' + timeNow;