-
- کد ملی برای احراز هویت شاهکار در خریدهای با مبلغ بالا لازم است.
-
+ {!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;
};