Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.

Commit

Permalink
add: application round send results
Browse files Browse the repository at this point in the history
  • Loading branch information
joonatank committed Nov 18, 2024
1 parent 3b7e1c4 commit d3fa402
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 8 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 @@ -7230,6 +7230,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 @@ -12749,6 +12757,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 @@ const 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
26 changes: 23 additions & 3 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 { Container, TabWrapper } from "@/styles/layout";
Expand Down Expand Up @@ -110,6 +111,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 @@ -121,6 +130,7 @@ function EndAllocation({
const { t } = useTranslation();

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

const handleEndAllocation = async () => {
try {
Expand Down Expand Up @@ -156,8 +166,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 @@ -293,6 +310,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 @@ -331,7 +351,7 @@ export function Review({
/>
</div>
) : null}
{!isHandled && (
{!hideAllocation && (
<AllocationButtonContainer>
{isAllocationEnabled ? (
<ButtonLikeLink to="allocation" variant="primary" size="large">
Expand Down

0 comments on commit d3fa402

Please sign in to comment.