Skip to content

Commit

Permalink
fix: dont allow reject if not in allocation state
Browse files Browse the repository at this point in the history
  • Loading branch information
joonatank committed May 8, 2024
1 parent bd30763 commit b717e05
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion apps/admin-ui/src/spa/applications/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,11 @@ function SchedulesContent({

function RejectOptionButton({
option,
applicationStatus,
refetch,
}: {
option: ReservationUnitOptionNode;
applicationStatus: ApplicationStatusChoice;
refetch: () => Promise<ApolloQueryResult<Query>>;
}) {
const [mutation, { loading }] = useMutation<
Expand Down Expand Up @@ -409,7 +411,8 @@ function RejectOptionButton({
console.warn("no allocatedTimeSlots", option);
}

const isDisabled = option.allocatedTimeSlots?.length > 0;
const canReject = applicationStatus === ApplicationStatusChoice.InAllocation;
const isDisabled = !canReject || option.allocatedTimeSlots?.length > 0;
return (
<Button
variant="supplementary"
Expand Down Expand Up @@ -497,6 +500,9 @@ function ApplicationSectionDetails({
return (
<RejectOptionButton
option={reservationUnitOption}
applicationStatus={
application.status ?? ApplicationStatusChoice.Draft
}
refetch={refetch}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion apps/admin-ui/src/spa/applications/queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const APPLICATION_ADMIN_QUERY = gql`
${APPLICATION_ADMIN_FRAGMENT}
query ApplicationAdmin($id: ID!) {
application(id: $id) {
...ApplicationCommon
...ApplicationAdminFragment
workingMemo
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/common/src/queries/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ const APPLICATION_ROUND_FRAGMENT = gql`
export const APPLICATION_ADMIN_FRAGMENT = gql`
${APPLICANT_FRAGMENT}
${APPLICATION_SECTION_UI_FRAGMENT}
fragment ApplicationCommon on ApplicationNode {
fragment ApplicationAdminFragment on ApplicationNode {
pk
id
status
lastModifiedDate
...ApplicantFragment
Expand All @@ -215,6 +216,7 @@ export const APPLICATION_ADMIN_FRAGMENT = gql`
rejected
allocatedTimeSlots {
pk
id
}
}
}
Expand Down

0 comments on commit b717e05

Please sign in to comment.