Skip to content

Commit

Permalink
finished year check for program outcomes submission and set model mem…
Browse files Browse the repository at this point in the history
…ber status when adding/editing orgs
  • Loading branch information
charlesjin123 committed Jan 11, 2025
1 parent 2a9ddbb commit 51218ab
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 15 deletions.
13 changes: 13 additions & 0 deletions client/src/AddOrganization/AddOrganization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,19 @@ export default function AddOrganization() {
/>
</Grid>

<Grid item xs={12} sm={6}>
<TextField
select
label="Status"
value={newOrg.status}
onChange={(e) => setNewOrg({ ...newOrg, status: e.target.value })}
fullWidth
>
<MenuItem value="Member">Member</MenuItem>
<MenuItem value="Model Member">Model Member</MenuItem>
</TextField>
</Grid>

<Grid item xs={12}>
<Button
fullWidth
Expand Down
29 changes: 21 additions & 8 deletions client/src/EditOrganization/EditOrganization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,15 @@ export default function EditOrganization() {
console.log(result);
if (result) {
const { data } = result;
setNewOrg({
...newOrg,
organizationName: data?.organizationName,
street: data?.street,
city: data?.city,
state: data?.state,
zip: data?.zip,
});
// setNewOrg({
// ...newOrg,
// organizationName: data?.organizationName,
// street: data?.street,
// city: data?.city,
// state: data?.state,
// zip: data?.zip,
// });
setNewOrg(data);
} else {
console.log('No available organization');
}
Expand Down Expand Up @@ -228,6 +229,18 @@ export default function EditOrganization() {
}}
/>
</Grid>
<Grid item xs={12} sm={6}>
<TextField
select
label="Status"
value={newOrg.status}
onChange={(e) => setNewOrg({ ...newOrg, status: e.target.value })}
fullWidth
>
<MenuItem value="Member">Member</MenuItem>
<MenuItem value="Model Member">Model Member</MenuItem>
</TextField>
</Grid>

<Grid item xs={12}>
<Button
Expand Down
34 changes: 31 additions & 3 deletions client/src/SubmissionForms/ProgramOutcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from '@mui/material';
import { Link } from 'react-router-dom';
import { useSelector } from 'react-redux';
import { postData } from '../util/api';
import { getData, postData } from '../util/api';
import { RootState } from '../util/redux/store';

export default function ProgramOutcome() {
Expand Down Expand Up @@ -374,10 +374,38 @@ export default function ProgramOutcome() {

const [errorOpen, setErrorOpen] = useState(false);
const [errorMessages, setErrorMessages] = useState<string[]>([]);
const validateInputs = () => {
const validateInputs = async () => {
console.log('Validating inputs');
let hasError = false;
const allErrorMessages: string[] = [];

const year = formState.currYear;

if (
Number.isNaN(year) ||
year < 2017 ||
year > new Date().getFullYear() + 5
) {
hasError = true;
console.log('year:', year);
allErrorMessages.push('The year is too old or too far in the future.');
} else {
try {
console.log('Checking year:', year);
const response = await getData(
`program_outcomes/org/${formState.orgId}/${year - 2}`,
);
console.log('Response:', response);
console.log(response.data != null);
if (response.data != null && response.data !== '') {
hasError = true;
allErrorMessages.push('A submission for this year already exists.');
}
} catch (error) {
console.error('Error checking year:', error);
}
}

if (
formState.programCostPerTrainee !== undefined &&
formState.programCostPerTrainee < 0
Expand Down Expand Up @@ -900,7 +928,7 @@ export default function ProgramOutcome() {
};
const handleSubmit = async () => {
console.log('handling submit');
if (validateInputs()) {
if (await validateInputs()) {
try {
const formData = {
...formState,
Expand Down
9 changes: 6 additions & 3 deletions server/src/controllers/organization.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const addOrganizationController = async (
res: express.Response,
next: express.NextFunction,
) => {
console.log('Add org controller');
console.log(req.body);
const { status, street, city, zip, state, organizationName } = req.body;
addOrganization(status, street, city, state, zip, organizationName)
.then((org: unknown) => {
Expand Down Expand Up @@ -110,8 +112,9 @@ const editOrganizationController = async (
res: express.Response,
next: express.NextFunction,
) => {
const { id, organizationName, status, street, city, state, zip } = req.body;
if (!id) {
const { _id, organizationName, status, street, city, state, zip } = req.body;
console.log(req.body);
if (!_id) {
next(ApiError.missingFields(['id']));
}
try {
Expand All @@ -120,7 +123,7 @@ const editOrganizationController = async (
const org = await editOrganization(
status,
organizationName,
id,
_id,
street,
city,
state,
Expand Down
2 changes: 1 addition & 1 deletion server/src/models/organization.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const OrganizationSchema = new mongoose.Schema(
},
status: {
type: String,
enum: ['Member', 'DJIBRIL', 'Model Member'],
enum: ['Member', 'Model Member'],
required: true,
},
street: { type: String, required: true },
Expand Down

0 comments on commit 51218ab

Please sign in to comment.