From e44b15ecd540b127dbab1324b49e800f35ab1319 Mon Sep 17 00:00:00 2001 From: Fred KISSIE Date: Wed, 4 Mar 2026 01:54:50 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8set=20opt=20email=20whitelist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EditPolicyOtpEmailSectionForm.tsx | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/components/resource-policy/EditPolicyOtpEmailSectionForm.tsx b/src/components/resource-policy/EditPolicyOtpEmailSectionForm.tsx index 93cb2b295..842fc0564 100644 --- a/src/components/resource-policy/EditPolicyOtpEmailSectionForm.tsx +++ b/src/components/resource-policy/EditPolicyOtpEmailSectionForm.tsx @@ -16,6 +16,10 @@ import z from "zod"; import { createPolicySchema, type PolicyFormValues } from "."; +import { toast } from "@app/hooks/useToast"; +import { createApiClient, formatAxiosError } from "@app/lib/api"; +import { useEnvContext } from "@app/hooks/useEnvContext"; +import type { AxiosResponse } from "axios"; import { SwitchInput } from "@app/components/SwitchInput"; import { Tag, TagInput } from "@app/components/tags/tag-input"; import { Alert, AlertDescription, AlertTitle } from "@app/components/ui/alert"; @@ -52,6 +56,8 @@ export function EditPolicyOtpEmailSectionForm({ const { policy } = useResourcePolicyContext(); const router = useRouter(); + const api = createApiClient(useEnvContext()); + const form = useForm({ resolver: zodResolver( createPolicySchema.pick({ @@ -87,7 +93,40 @@ export function EditPolicyOtpEmailSectionForm({ const payload = form.getValues(); - console.log({ payload, policy }); + try { + const res = await api + .put>( + `/resource-policy/${policy.resourcePolicyId}/whitelist`, + { + emailWhitelistEnabled: payload.emailWhitelistEnabled, + emails: payload.emails?.map((e) => e.text) ?? [] + } + ) + .catch((e) => { + toast({ + variant: "destructive", + title: t("policyErrorUpdate"), + description: formatAxiosError( + e, + t("policyErrorUpdateDescription") + ) + }); + }); + + if (res && res.status === 200) { + toast({ + title: t("success"), + description: t("policyUpdatedSuccess") + }); + router.refresh(); + } + } catch (e) { + toast({ + variant: "destructive", + title: t("policyErrorUpdate"), + description: t("policyErrorUpdateMessageDescription") + }); + } } if (!isExpanded) {