Skip to content

Commit 7ad27ef

Browse files
authored
ORV2-5096 - FE: Revoke permit causes unexpected error (#2178)
Co-authored-by: GlenAOT <160973940+GlenAOT@users.noreply.github.com>
1 parent 17aad69 commit 7ad27ef

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

frontend/src/features/permits/pages/Void/components/VoidPermitForm.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ import { useVoidOrRevokePermit } from "../hooks/useVoidOrRevokePermit";
1717
import { mapToRevokeRequestData } from "../helpers/mapper";
1818
import { ORBC_FORM_FEATURES } from "../../../../../common/types/common";
1919
import { hasPermitsActionFailed } from "../../../helpers/permitState";
20-
import { usePermitHistoryQuery } from "../../../hooks/hooks";
20+
import {
21+
useAmendmentApplicationQuery,
22+
useDeleteApplicationsMutation,
23+
usePermitHistoryQuery,
24+
} from "../../../hooks/hooks";
2125
import { isValidTransaction } from "../../../helpers/payment";
2226
import {
2327
invalidEmail,
@@ -108,7 +112,23 @@ export const VoidPermitForm = () => {
108112
setOpenRevokeDialog(false);
109113
};
110114

111-
const handleRevoke = (revokeData: VoidPermitFormData) => {
115+
const { data: existingAmendmentApplication } = useAmendmentApplicationQuery(
116+
companyId,
117+
originalPermitId,
118+
);
119+
120+
const existingAmendmentApplicationId = existingAmendmentApplication?.permitId;
121+
122+
const { mutateAsync: deleteApplications } = useDeleteApplicationsMutation();
123+
124+
const handleRevoke = async (revokeData: VoidPermitFormData) => {
125+
// if there is an amendment in progress for this application, delete it. This will prevent existing application errors from the backend when attempting to complete the revoke transaction
126+
if (existingAmendmentApplicationId) {
127+
await deleteApplications({
128+
companyId,
129+
applicationIds: [existingAmendmentApplicationId],
130+
});
131+
}
112132
revokePermitMutation.mutate({
113133
permitId,
114134
voidData: mapToRevokeRequestData(revokeData),

0 commit comments

Comments
 (0)