From c4c115ccfc47718dfe45103a0694133c509bbbb8 Mon Sep 17 00:00:00 2001 From: soheil khaledabadi Date: Sat, 17 Oct 2026 23:35:35 +0330 Subject: [PATCH] Lock verified identity fields in profile and checkout --- src/pages/profile/section/ProfileDetails.tsx | 4 +++ .../section/components/ModalEditProfile.tsx | 21 ++++++++++---- .../productList/components/ModalBuy.tsx | 28 ++++++++++++------- src/types/props.d.ts | 2 ++ 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/pages/profile/section/ProfileDetails.tsx b/src/pages/profile/section/ProfileDetails.tsx index a5cec46..8d0680b 100644 --- a/src/pages/profile/section/ProfileDetails.tsx +++ b/src/pages/profile/section/ProfileDetails.tsx @@ -17,6 +17,7 @@ const ProfileDetails = ({ return (
>; nationalId?: string | null; + identityVerified?: boolean; email?: string | null; mobile?: string | null; cardNumber?: string | null; @@ -66,7 +68,7 @@ const ModalEditProfile = ({ mutationFn: async () => { const requests = []; - if (nationalCode.trim() && nationalCode.trim() !== (nationalId ?? "")) { + if (!identityVerified && nationalCode.trim() && nationalCode.trim() !== (nationalId ?? "")) { requests.push( axios.post("/profile/national-id", { national_id: nationalCode.trim(), @@ -102,7 +104,7 @@ const ModalEditProfile = ({ }); const submitHandler = () => { - if (nationalCode.trim() && nationalCode.trim().length !== 10) { + if (!identityVerified && nationalCode.trim() && nationalCode.trim().length !== 10) { toast.error("کد ملی باید ۱۰ رقم باشد"); return; } @@ -203,7 +205,11 @@ const ModalEditProfile = ({ value={mobile ?? ""} disabled /> - {mobileStep === "idle" ? ( + {identityVerified ? ( + + شماره موبایل و کد ملی شما تأیید شده‌اند و قابل تغییر نیستند. + + ) : mobileStep === "idle" ? (
- - کد ملی برای احراز هویت شاهکار در خریدهای با مبلغ بالا لازم است. - + {!identityVerified && ( + + کد ملی برای احراز هویت شاهکار در خریدهای با مبلغ بالا لازم است. + + )} setNationalCode(e.target.value.replace(/[^0-9]/g, "")) } diff --git a/src/pages/shop/section/productList/components/ModalBuy.tsx b/src/pages/shop/section/productList/components/ModalBuy.tsx index 1ba0fc5..3e71009 100644 --- a/src/pages/shop/section/productList/components/ModalBuy.tsx +++ b/src/pages/shop/section/productList/components/ModalBuy.tsx @@ -47,6 +47,7 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => { const [isInfoOpen, setIsInfoOpen] = useState(false); const [needsShahkarVerification, setNeedsShahkarVerification] = useState(false); const [nationalCode, setNationalCode] = useState(""); + const identityVerified = Boolean(data?.data?.result?.is_identity_verified); const [hasReadDescription, setHasReadDescription] = useState(false); const payablePrice = toNumber( price === 0 ? data?.data?.result?.price || 0 : price @@ -113,6 +114,9 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => { }, [isOpen, setFieldValue]); const mutation = useMutation({ mutationKey: ["buyConfig"], + onSettled: () => { + queryClient.invalidateQueries({ queryKey: ["profile"] }); + }, mutationFn: (values: BuyConfigDataProps) => { return axios.post(`home/config/${configId}/buy`, values); }, @@ -205,7 +209,7 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => { return; } - if (needsShahkarVerification && nationalCode.trim().length !== 10) { + if (needsShahkarVerification && !identityVerified && nationalCode.trim().length !== 10) { toast.error("لطفا کد ملی ۱۰ رقمی را به‌درستی وارد کنید"); return; } @@ -214,7 +218,7 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => { ...formik.values, status: "buy", ...(hasExtraDescription ? { hasReadDescription: true } : {}), - ...(needsShahkarVerification ? { nationalCode: nationalCode.trim() } : {}), + ...(needsShahkarVerification && !identityVerified ? { nationalCode: nationalCode.trim() } : {}), }; toast.promise(mutation.mutateAsync(payload), { @@ -239,6 +243,9 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => { } const responseData = err.response?.data; + if (responseData && typeof responseData === "object" && "message" in responseData && typeof responseData.message === "string") { + errorMessage = responseData.message; + } const isResponseObject = responseData !== null && typeof responseData === "object"; const requiresAdvancedVerificationFromApi = @@ -256,13 +263,14 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => { (err.response?.status === 422 && errorMessage.includes("احراز هویت پیشرفته")); - const requiresShahkarVerificationFromApi = - isResponseObject && - "requires_shahkar_verification" in responseData && - Boolean( - (responseData as { requires_shahkar_verification?: boolean }) - .requires_shahkar_verification - ); + const shahkarError = responseData as { + requires_shahkar_verification?: boolean; + result?: { requires_shahkar_verification?: boolean }; + } | undefined; + const requiresShahkarVerificationFromApi = Boolean( + shahkarError?.requires_shahkar_verification || + shahkarError?.result?.requires_shahkar_verification + ); if (requiresShahkarVerificationFromApi) { setNeedsShahkarVerification(true); @@ -382,7 +390,7 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => { {advancedVerificationMessage} )} - {needsShahkarVerification && ( + {needsShahkarVerification && !identityVerified && (
برای خریدهای با مبلغ بالا، احراز هویت شاهکار (تطبیق شماره diff --git a/src/types/props.d.ts b/src/types/props.d.ts index 038fc31..cd7b5b0 100644 --- a/src/types/props.d.ts +++ b/src/types/props.d.ts @@ -219,6 +219,8 @@ type UserProfile = { email: string; mobile: string; national_id?: string | null; + is_identity_verified?: boolean; + shahkar_verified_at?: string | null; card_number?: string | null; };