Skip to content

Commit

Permalink
add: application round send results
Browse files Browse the repository at this point in the history
  • Loading branch information
joonatank committed Jan 8, 2025
1 parent 1267265 commit cadf795
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 14 deletions.
58 changes: 58 additions & 0 deletions apps/admin-ui/gql/gql-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7050,6 +7050,14 @@ export type EndAllocationMutation = {
setApplicationRoundHandled?: { pk?: number | null } | null;
};

export type SendResultsMutationVariables = Exact<{
pk: Scalars["Int"]["input"];
}>;

export type SendResultsMutation = {
setApplicationRoundResultsSent?: { pk?: number | null } | null;
};

export type ApplicationsQueryVariables = Exact<{
applicationRound: Scalars["Int"]["input"];
unit?: InputMaybe<
Expand Down Expand Up @@ -12681,6 +12689,56 @@ export type EndAllocationMutationOptions = Apollo.BaseMutationOptions<
EndAllocationMutation,
EndAllocationMutationVariables
>;
export const SendResultsDocument = gql`
mutation SendResults($pk: Int!) {
setApplicationRoundResultsSent(input: { pk: $pk }) {
pk
}
}
`;
export type SendResultsMutationFn = Apollo.MutationFunction<
SendResultsMutation,
SendResultsMutationVariables
>;

/**
* __useSendResultsMutation__
*
* To run a mutation, you first call `useSendResultsMutation` within a React component and pass it any options that fit your needs.
* When your component renders, `useSendResultsMutation` returns a tuple that includes:
* - A mutate function that you can call at any time to execute the mutation
* - An object with fields that represent the current status of the mutation's execution
*
* @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2;
*
* @example
* const [sendResultsMutation, { data, loading, error }] = useSendResultsMutation({
* variables: {
* pk: // value for 'pk'
* },
* });
*/
export function useSendResultsMutation(
baseOptions?: Apollo.MutationHookOptions<
SendResultsMutation,
SendResultsMutationVariables
>
) {
const options = { ...defaultOptions, ...baseOptions };
return Apollo.useMutation<SendResultsMutation, SendResultsMutationVariables>(
SendResultsDocument,
options
);
}
export type SendResultsMutationHookResult = ReturnType<
typeof useSendResultsMutation
>;
export type SendResultsMutationResult =
Apollo.MutationResult<SendResultsMutation>;
export type SendResultsMutationOptions = Apollo.BaseMutationOptions<
SendResultsMutation,
SendResultsMutationVariables
>;
export const ApplicationsDocument = gql`
query Applications(
$applicationRound: Int!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,35 @@ export function getApplicationRoundStatus(
group: "g1",
type: "alert",
icon: <IconClock aria-hidden="true" />,
label: ApplicationRoundStatusChoice.Open,
label: status,
};
case ApplicationRoundStatusChoice.InAllocation:
return {
group: "g1",
type: "info",
icon: <IconCogwheel aria-hidden="true" />,
label: ApplicationRoundStatusChoice.InAllocation,
label: status,
};
case ApplicationRoundStatusChoice.Handled:
return {
group: "g2",
type: "success",
icon: <IconCheck aria-hidden="true" />,
label: ApplicationRoundStatusChoice.Handled,
label: status,
};
case ApplicationRoundStatusChoice.ResultsSent:
return {
group: "g2",
type: "success",
icon: <IconEnvelope aria-hidden="true" />,
label: ApplicationRoundStatusChoice.Handled,
label: status,
};
case ApplicationRoundStatusChoice.Upcoming:
return {
group: "g4",
type: "draft",
icon: <IconArrowTopRight aria-hidden="true" />,
label: ApplicationRoundStatusChoice.Upcoming,
label: status,
};
default:
return {
Expand Down
38 changes: 29 additions & 9 deletions apps/admin-ui/src/spa/application-rounds/[id]/review/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ApplicationRoundReservationCreationStatusChoice,
type ApplicationRoundQuery,
UserPermissionChoice,
useSendResultsMutation,
} from "@gql/gql-types";
import { ButtonLikeLink } from "@/component/ButtonLikeLink";
import { ApplicationRoundStatusLabel } from "../../ApplicationRoundStatusLabel";
Expand Down Expand Up @@ -78,6 +79,14 @@ export const END_ALLOCATION_MUTATION = gql`
}
`;

export const SEND_RESULTS_MUTATION = gql`
mutation SendResults($pk: Int!) {
setApplicationRoundResultsSent(input: { pk: $pk }) {
pk
}
}
`;

function EndAllocation({
applicationRound,
refetch,
Expand All @@ -89,6 +98,7 @@ function EndAllocation({
const { t } = useTranslation();

const [mutation] = useEndAllocationMutation();
const [sendResults] = useSendResultsMutation();

const handleEndAllocation = async () => {
try {
Expand Down Expand Up @@ -124,8 +134,15 @@ function EndAllocation({
refetch();
};

const handleSendResults = () => {
errorToast({ text: "TODO: not implemented handleSendResults" });
const handleSendResults = async () => {
try {
await sendResults({
variables: { pk: applicationRound.pk ?? 0 },
});
} catch (err) {
errorToast({ text: t("errors.errorSendingResults") });
}
refetch();
};

const hasFailed =
Expand Down Expand Up @@ -261,6 +278,9 @@ export function Review({
// i.e. state.InAllocation -> isSettingHandledAllowed -> state.Handled -> state.ResultsSent
const isHandled =
applicationRound.status === ApplicationRoundStatusChoice.Handled;
const isResultsSent =
applicationRound.status === ApplicationRoundStatusChoice.ResultsSent;
const hideAllocation = isHandled || isResultsSent;

const isEndingAllowed = applicationRound.isSettingHandledAllowed;

Expand Down Expand Up @@ -294,7 +314,13 @@ export function Review({
$direction="row-reverse"
$alignItems="center"
>
{!isHandled && (
{isEndingAllowed || isHandled ? (
<EndAllocation
applicationRound={applicationRound}
refetch={refetch}
/>
) : null}
{!hideAllocation && (
<>
{isAllocationEnabled ? (
<ButtonLikeLink to="allocation" variant="primary" size="large">
Expand All @@ -307,12 +333,6 @@ export function Review({
)}
</>
)}
{isEndingAllowed || isHandled ? (
<EndAllocation
applicationRound={applicationRound}
refetch={refetch}
/>
) : null}
</Flex>
<TabWrapper>
<Tabs initiallyActiveTab={activeTabIndex}>
Expand Down

0 comments on commit cadf795

Please sign in to comment.