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

set and get due date #2172

Merged
merged 3 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/services/housing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const getAllApplicant = (): Promise<ApartmentHall[]> =>
http.get('housing/housing_lottery/all_applicant');
const getAllSchoolYear = (): Promise<ApartmentHall[]> =>
http.get('housing/housing_lottery/all_school_year');
const getDueDate = (): Promise<ApartmentHall[]> => http.get('housing/housing_lottery/get_due_date');

const getCurrentApplicationID = (username: string = ''): Promise<number> =>
http.get(username ? `housing/apartment/${username}/` : 'housing/apartment/');
Expand Down Expand Up @@ -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,
Expand All @@ -190,6 +193,7 @@ const housingService = {
getAllPreferredHall,
getAllApplicant,
getAllSchoolYear,
getDueDate,
getCurrentApplicationID,
saveApartmentApplication,
deleteApartmentApplication,
Expand All @@ -200,6 +204,7 @@ const housingService = {
addApplicant,
addHall,
addPreference,
addDueDate,
};

export default housingService;
41 changes: 41 additions & 0 deletions src/views/HousingLottery/adminView/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import {
Card,
CardHeader,
CardContent,
TextField,
Link,
} from '@mui/material';
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([]);
Expand All @@ -26,12 +28,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) => ({
Expand Down Expand Up @@ -74,10 +78,47 @@ 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);
};

return (
<Grid container justifyContent="center">
<Grid item xs={12} lg={8}>
<Grid>
<TextField
type="text"
variant="outlined"
color="secondary"
label="Due Date"
value={dueDate}
onChange={handleDateChange}
margin="normal"
helperText="* MM/DD/YYYY"
/>
<Button
className={styles.submit_button}
variant="contained"
onClick={submitDueDate}
>
Submit
</Button>
</Grid>
<Card>
<CardHeader title="Admin Interface" className={styles.admin_card_header} />
<CardContent>
Expand Down
15 changes: 13 additions & 2 deletions src/views/HousingLottery/studentView/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -41,7 +46,13 @@ const StudentView = () => {

const handleClick = async () => {
try {
console.log(application_id);
let application_id = nanoid(8),
timeTarget = new Date(dueDate + ' 11:59:59 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);
Expand Down
Loading