diff --git a/client/src/components/ApplicationRejectButton/ApplicationRejectButton.tsx b/client/src/components/ApplicationRejectButton/ApplicationRejectButton.tsx index 76c3db5b..5a56256e 100644 --- a/client/src/components/ApplicationRejectButton/ApplicationRejectButton.tsx +++ b/client/src/components/ApplicationRejectButton/ApplicationRejectButton.tsx @@ -13,6 +13,11 @@ interface IApplicationRejectButtonProps extends ButtonProps { onUpdate: (application: IApplication) => unknown } +interface IFormValues { + notifyUser: boolean + reason: string | null +} + const ApplicationRejectButton = (props: IApplicationRejectButtonProps) => { const { application, onUpdate, ...buttonProps } = props @@ -21,10 +26,7 @@ const ApplicationRejectButton = (props: IApplicationRejectButtonProps) => { const [confirmationModal, setConfirmationModal] = useState(false) const [loading, setLoading] = useState(false) - const form = useForm<{ - notifyUser: boolean - reason: string | null - }>({ + const form = useForm({ mode: 'controlled', initialValues: { notifyUser: true, @@ -44,6 +46,46 @@ const ApplicationRejectButton = (props: IApplicationRejectButtonProps) => { return <> } + const onReject = async (values: IFormValues) => { + setLoading(true) + + try { + const response = await doRequest( + `/v2/applications/${application.applicationId}/reject`, + { + method: 'PUT', + requiresAuth: true, + data: { + reason: values.reason, + notifyUser: values.notifyUser, + }, + }, + ) + + if (response.ok) { + showSimpleSuccess('Application rejected successfully') + + for (const item of response.data) { + updateApplicationContext(item) + } + + const currentApplication = response.data.find( + (item) => item.applicationId === application.applicationId, + ) + + if (currentApplication) { + onUpdate(currentApplication) + } + + setConfirmationModal(false) + } else { + showSimpleError(getApiResponseErrorMessage(response)) + } + } finally { + setLoading(false) + } + } + const reasons: Array<{ value: string; label: string }> = [ application.topic ? { @@ -78,47 +120,7 @@ const ApplicationRejectButton = (props: IApplicationRejectButtonProps) => { onClick={(e) => e.stopPropagation()} onClose={() => setConfirmationModal(false)} > -
{ - setLoading(true) - - try { - const response = await doRequest( - `/v2/applications/${application.applicationId}/reject`, - { - method: 'PUT', - requiresAuth: true, - data: { - reason: values.reason, - notifyUser: values.notifyUser, - }, - }, - ) - - if (response.ok) { - showSimpleSuccess('Application rejected successfully') - - for (const item of response.data) { - updateApplicationContext(item) - } - - const currentApplication = response.data.find( - (item) => item.applicationId === application.applicationId, - ) - - if (currentApplication) { - onUpdate(currentApplication) - } - - setConfirmationModal(false) - } else { - showSimpleError(getApiResponseErrorMessage(response)) - } - } finally { - setLoading(false) - } - })} - > + Please specify a reason why you want to reject the student @@ -133,7 +135,12 @@ const ApplicationRejectButton = (props: IApplicationRejectButtonProps) => { required {...form.getInputProps('notifyUser', { type: 'checkbox' })} /> - diff --git a/client/src/components/ApplicationReviewForm/ApplicationReviewForm.tsx b/client/src/components/ApplicationReviewForm/ApplicationReviewForm.tsx index ce900c6d..b4c03848 100644 --- a/client/src/components/ApplicationReviewForm/ApplicationReviewForm.tsx +++ b/client/src/components/ApplicationReviewForm/ApplicationReviewForm.tsx @@ -123,7 +123,7 @@ const ApplicationReviewForm = (props: IApplicationReviewFormProps) => { } }, [debouncedComment, application?.applicationId]) - const onSubmit = async (values: IApplicationReviewForm) => { + const onAccept = async (values: IApplicationReviewForm) => { setLoading(true) try { @@ -204,7 +204,7 @@ const ApplicationReviewForm = (props: IApplicationReviewFormProps) => { } return ( - onSubmit(values))}> + {reviewers.map((reviewer) => ( @@ -296,7 +296,7 @@ const ApplicationReviewForm = (props: IApplicationReviewFormProps) => { }} />