Skip to content

Commit

Permalink
Check declaration: handle potential API validation errors (#926)
Browse files Browse the repository at this point in the history
  • Loading branch information
bloodyowl authored Oct 1, 2024
1 parent 67a64bc commit 6b66cc0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
15 changes: 14 additions & 1 deletion clients/banking/src/components/CheckDeclarationWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export const CheckDeclarationWizard = ({ merchantProfileId, params }: Props) =>
const [declareOne, declareOneData] = useMutation(InitiateCheckMerchantPaymentDocument);
const [declareAndAdd, declareAndAddData] = useMutation(InitiateCheckMerchantPaymentDocument);

const { Field, resetForm, submitForm } = useForm({
const { Field, resetForm, submitForm, setFieldError } = useForm({
label: {
initialValue: "",
sanitize: trim,
Expand Down Expand Up @@ -307,6 +307,19 @@ export const CheckDeclarationWizard = ({ merchantProfileId, params }: Props) =>
.with({ __typename: "CheckRejection" }, ({ fnciInfo }) => {
setFnciError(fnciInfo);
})
.with({ __typename: "ValidationRejection" }, ({ fields }) => {
fields.forEach(field => {
match(field.path)
.with(["amount"], () =>
setFieldError("amount", t("common.form.invalidAmount")),
)
.with(["cmc7"], () => setFieldError("cmc7", t("common.form.invalidCMC7")))
.with(["rlmcKey"], () =>
setFieldError("rlmcKey", t("common.form.invalidRLMC")),
)
.otherwise(() => {});
});
})
.otherwise(error => {
showToast({
variant: "error",
Expand Down
5 changes: 5 additions & 0 deletions clients/banking/src/graphql/partner.gql
Original file line number Diff line number Diff line change
Expand Up @@ -2796,6 +2796,11 @@ mutation InitiateCheckMerchantPayment($input: InitiateCheckMerchantPaymentInput!
...FnciInfo
}
}
... on ValidationRejection {
fields {
path
}
}
... on Rejection {
message
}
Expand Down

0 comments on commit 6b66cc0

Please sign in to comment.