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

Fix reject button handling when reviewing applications #296

Merged
merged 1 commit into from
Oct 4, 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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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<IFormValues>({
mode: 'controlled',
initialValues: {
notifyUser: true,
Expand All @@ -44,6 +46,46 @@ const ApplicationRejectButton = (props: IApplicationRejectButtonProps) => {
return <></>
}

const onReject = async (values: IFormValues) => {
setLoading(true)

try {
const response = await doRequest<IApplication[]>(
`/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
? {
Expand Down Expand Up @@ -78,47 +120,7 @@ const ApplicationRejectButton = (props: IApplicationRejectButtonProps) => {
onClick={(e) => e.stopPropagation()}
onClose={() => setConfirmationModal(false)}
>
<form
onSubmit={form.onSubmit(async (values) => {
setLoading(true)

try {
const response = await doRequest<IApplication[]>(
`/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)
}
})}
>
<form>
<Stack>
<Text>Please specify a reason why you want to reject the student</Text>
<Radio.Group label='Reason' required {...form.getInputProps('reason')}>
Expand All @@ -133,7 +135,12 @@ const ApplicationRejectButton = (props: IApplicationRejectButtonProps) => {
required
{...form.getInputProps('notifyUser', { type: 'checkbox' })}
/>
<Button type='submit' loading={loading} disabled={!form.isValid()} fullWidth>
<Button
onClick={() => onReject(form.getValues())}
loading={loading}
disabled={!form.isValid()}
fullWidth
>
Reject Application
</Button>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const ApplicationReviewForm = (props: IApplicationReviewFormProps) => {
}
}, [debouncedComment, application?.applicationId])

const onSubmit = async (values: IApplicationReviewForm) => {
const onAccept = async (values: IApplicationReviewForm) => {
setLoading(true)

try {
Expand Down Expand Up @@ -204,7 +204,7 @@ const ApplicationReviewForm = (props: IApplicationReviewFormProps) => {
}

return (
<form onSubmit={form.onSubmit((values) => onSubmit(values))}>
<form>
<Stack gap='sm'>
{reviewers.map((reviewer) => (
<Group key={reviewer.user.userId} grow wrap='nowrap'>
Expand Down Expand Up @@ -296,7 +296,7 @@ const ApplicationReviewForm = (props: IApplicationReviewFormProps) => {
}}
/>
<Button
type='submit'
onClick={() => onAccept(form.getValues())}
variant='outline'
color='green'
loading={loading}
Expand Down
1 change: 0 additions & 1 deletion server/mail-templates/thesis-final-submission.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
</p>

<p>
You can find the submitted files in the attachment part of this email.
The next step is to write an assessment about the thesis.
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ public void sendFinalSubmissionEmail(Thesis thesis) {
.sendToThesisAdvisors(thesis)
.addNotificationName("thesis-" + thesis.getId())
.fillThesisPlaceholders(thesis)
.addStoredAttachment(thesis.getFinalThesisFilename(), getThesisFilename(thesis, "File", thesis.getFinalThesisFilename()))
.addStoredAttachment(thesis.getFinalPresentationFilename(), getThesisFilename(thesis, "Presentation", thesis.getFinalPresentationFilename()))
//.addStoredAttachment(thesis.getFinalThesisFilename(), getThesisFilename(thesis, "File", thesis.getFinalThesisFilename()))
//.addStoredAttachment(thesis.getFinalPresentationFilename(), getThesisFilename(thesis, "Presentation", thesis.getFinalPresentationFilename()))
.send(javaMailSender, uploadService);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.mail.MailSendException;
import org.springframework.mail.javamail.JavaMailSender;
import thesistrack.ls1.constants.ThesisRoleName;
import thesistrack.ls1.dto.ApplicationDto;
Expand Down Expand Up @@ -368,7 +369,7 @@ public void send(JavaMailSender mailSender, UploadService uploadService) throws
} else {
log.info("Sending Mail (postfix disabled)\n{}", MailLogger.getTextFromMimeMessage(message));
}
} catch (MessagingException exception) {
} catch (Exception exception) {
log.warn("Failed to send email", exception);
}
}
Expand Down