Lock verified identity fields in profile and checkout
This commit is contained in:
@@ -17,6 +17,7 @@ const ProfileDetails = ({
|
|||||||
return (
|
return (
|
||||||
<div className="relative z-[10] w-full min-h-32 max-md:min-h-20 flex flex-row-reverse max-[400px]:gap-3 justify-between flex-wrap-reverse glass items-center py-2 px-4">
|
<div className="relative z-[10] w-full min-h-32 max-md:min-h-20 flex flex-row-reverse max-[400px]:gap-3 justify-between flex-wrap-reverse glass items-center py-2 px-4">
|
||||||
<EditProfile
|
<EditProfile
|
||||||
|
identityVerified={data?.result?.user_profile?.is_identity_verified}
|
||||||
nationalId={data?.result?.user_profile?.national_id}
|
nationalId={data?.result?.user_profile?.national_id}
|
||||||
email={data?.result?.user_profile?.email}
|
email={data?.result?.user_profile?.email}
|
||||||
mobile={data?.result?.user_profile?.mobile}
|
mobile={data?.result?.user_profile?.mobile}
|
||||||
@@ -36,11 +37,13 @@ const ProfileDetails = ({
|
|||||||
export default ProfileDetails;
|
export default ProfileDetails;
|
||||||
|
|
||||||
const EditProfile = ({
|
const EditProfile = ({
|
||||||
|
identityVerified,
|
||||||
nationalId,
|
nationalId,
|
||||||
email,
|
email,
|
||||||
mobile,
|
mobile,
|
||||||
cardNumber,
|
cardNumber,
|
||||||
}: {
|
}: {
|
||||||
|
identityVerified?: boolean;
|
||||||
nationalId?: string | null;
|
nationalId?: string | null;
|
||||||
email?: string | null;
|
email?: string | null;
|
||||||
mobile?: string | null;
|
mobile?: string | null;
|
||||||
@@ -53,6 +56,7 @@ const EditProfile = ({
|
|||||||
<ModalEditProfile
|
<ModalEditProfile
|
||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
setIsOpen={setIsOpen}
|
setIsOpen={setIsOpen}
|
||||||
|
identityVerified={identityVerified}
|
||||||
nationalId={nationalId}
|
nationalId={nationalId}
|
||||||
email={email}
|
email={email}
|
||||||
mobile={mobile}
|
mobile={mobile}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ const ModalEditProfile = ({
|
|||||||
isOpen,
|
isOpen,
|
||||||
setIsOpen,
|
setIsOpen,
|
||||||
nationalId,
|
nationalId,
|
||||||
|
identityVerified = false,
|
||||||
email,
|
email,
|
||||||
mobile,
|
mobile,
|
||||||
cardNumber,
|
cardNumber,
|
||||||
@@ -33,6 +34,7 @@ const ModalEditProfile = ({
|
|||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
setIsOpen: Dispatch<SetStateAction<boolean>>;
|
setIsOpen: Dispatch<SetStateAction<boolean>>;
|
||||||
nationalId?: string | null;
|
nationalId?: string | null;
|
||||||
|
identityVerified?: boolean;
|
||||||
email?: string | null;
|
email?: string | null;
|
||||||
mobile?: string | null;
|
mobile?: string | null;
|
||||||
cardNumber?: string | null;
|
cardNumber?: string | null;
|
||||||
@@ -66,7 +68,7 @@ const ModalEditProfile = ({
|
|||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
const requests = [];
|
const requests = [];
|
||||||
|
|
||||||
if (nationalCode.trim() && nationalCode.trim() !== (nationalId ?? "")) {
|
if (!identityVerified && nationalCode.trim() && nationalCode.trim() !== (nationalId ?? "")) {
|
||||||
requests.push(
|
requests.push(
|
||||||
axios.post("/profile/national-id", {
|
axios.post("/profile/national-id", {
|
||||||
national_id: nationalCode.trim(),
|
national_id: nationalCode.trim(),
|
||||||
@@ -102,7 +104,7 @@ const ModalEditProfile = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const submitHandler = () => {
|
const submitHandler = () => {
|
||||||
if (nationalCode.trim() && nationalCode.trim().length !== 10) {
|
if (!identityVerified && nationalCode.trim() && nationalCode.trim().length !== 10) {
|
||||||
toast.error("کد ملی باید ۱۰ رقم باشد");
|
toast.error("کد ملی باید ۱۰ رقم باشد");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -203,7 +205,11 @@ const ModalEditProfile = ({
|
|||||||
value={mobile ?? ""}
|
value={mobile ?? ""}
|
||||||
disabled
|
disabled
|
||||||
/>
|
/>
|
||||||
{mobileStep === "idle" ? (
|
{identityVerified ? (
|
||||||
|
<Alert type="info" extra="!mb-0 text-start">
|
||||||
|
شماره موبایل و کد ملی شما تأیید شدهاند و قابل تغییر نیستند.
|
||||||
|
</Alert>
|
||||||
|
) : mobileStep === "idle" ? (
|
||||||
<div className="w-full flex flex-col gap-2">
|
<div className="w-full flex flex-col gap-2">
|
||||||
<Input
|
<Input
|
||||||
type="text"
|
type="text"
|
||||||
@@ -301,9 +307,11 @@ const ModalEditProfile = ({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{!identityVerified && (
|
||||||
<Alert type="warning" extra="!mb-0 text-start">
|
<Alert type="warning" extra="!mb-0 text-start">
|
||||||
کد ملی برای احراز هویت شاهکار در خریدهای با مبلغ بالا لازم است.
|
کد ملی برای احراز هویت شاهکار در خریدهای با مبلغ بالا لازم است.
|
||||||
</Alert>
|
</Alert>
|
||||||
|
)}
|
||||||
<Input
|
<Input
|
||||||
type="text"
|
type="text"
|
||||||
label="کد ملی :"
|
label="کد ملی :"
|
||||||
@@ -311,6 +319,7 @@ const ModalEditProfile = ({
|
|||||||
extra="!w-full"
|
extra="!w-full"
|
||||||
placeholder="کد ملی ۱۰ رقمی"
|
placeholder="کد ملی ۱۰ رقمی"
|
||||||
value={nationalCode}
|
value={nationalCode}
|
||||||
|
disabled={identityVerified}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
setNationalCode(e.target.value.replace(/[^0-9]/g, ""))
|
setNationalCode(e.target.value.replace(/[^0-9]/g, ""))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
|||||||
const [isInfoOpen, setIsInfoOpen] = useState(false);
|
const [isInfoOpen, setIsInfoOpen] = useState(false);
|
||||||
const [needsShahkarVerification, setNeedsShahkarVerification] = useState(false);
|
const [needsShahkarVerification, setNeedsShahkarVerification] = useState(false);
|
||||||
const [nationalCode, setNationalCode] = useState("");
|
const [nationalCode, setNationalCode] = useState("");
|
||||||
|
const identityVerified = Boolean(data?.data?.result?.is_identity_verified);
|
||||||
const [hasReadDescription, setHasReadDescription] = useState(false);
|
const [hasReadDescription, setHasReadDescription] = useState(false);
|
||||||
const payablePrice = toNumber(
|
const payablePrice = toNumber(
|
||||||
price === 0 ? data?.data?.result?.price || 0 : price
|
price === 0 ? data?.data?.result?.price || 0 : price
|
||||||
@@ -113,6 +114,9 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
|||||||
}, [isOpen, setFieldValue]);
|
}, [isOpen, setFieldValue]);
|
||||||
const mutation = useMutation({
|
const mutation = useMutation({
|
||||||
mutationKey: ["buyConfig"],
|
mutationKey: ["buyConfig"],
|
||||||
|
onSettled: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["profile"] });
|
||||||
|
},
|
||||||
mutationFn: (values: BuyConfigDataProps) => {
|
mutationFn: (values: BuyConfigDataProps) => {
|
||||||
return axios.post(`home/config/${configId}/buy`, values);
|
return axios.post(`home/config/${configId}/buy`, values);
|
||||||
},
|
},
|
||||||
@@ -205,7 +209,7 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needsShahkarVerification && nationalCode.trim().length !== 10) {
|
if (needsShahkarVerification && !identityVerified && nationalCode.trim().length !== 10) {
|
||||||
toast.error("لطفا کد ملی ۱۰ رقمی را بهدرستی وارد کنید");
|
toast.error("لطفا کد ملی ۱۰ رقمی را بهدرستی وارد کنید");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -214,7 +218,7 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
|||||||
...formik.values,
|
...formik.values,
|
||||||
status: "buy",
|
status: "buy",
|
||||||
...(hasExtraDescription ? { hasReadDescription: true } : {}),
|
...(hasExtraDescription ? { hasReadDescription: true } : {}),
|
||||||
...(needsShahkarVerification ? { nationalCode: nationalCode.trim() } : {}),
|
...(needsShahkarVerification && !identityVerified ? { nationalCode: nationalCode.trim() } : {}),
|
||||||
};
|
};
|
||||||
|
|
||||||
toast.promise(mutation.mutateAsync(payload), {
|
toast.promise(mutation.mutateAsync(payload), {
|
||||||
@@ -239,6 +243,9 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const responseData = err.response?.data;
|
const responseData = err.response?.data;
|
||||||
|
if (responseData && typeof responseData === "object" && "message" in responseData && typeof responseData.message === "string") {
|
||||||
|
errorMessage = responseData.message;
|
||||||
|
}
|
||||||
const isResponseObject =
|
const isResponseObject =
|
||||||
responseData !== null && typeof responseData === "object";
|
responseData !== null && typeof responseData === "object";
|
||||||
const requiresAdvancedVerificationFromApi =
|
const requiresAdvancedVerificationFromApi =
|
||||||
@@ -256,12 +263,13 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
|||||||
(err.response?.status === 422 &&
|
(err.response?.status === 422 &&
|
||||||
errorMessage.includes("احراز هویت پیشرفته"));
|
errorMessage.includes("احراز هویت پیشرفته"));
|
||||||
|
|
||||||
const requiresShahkarVerificationFromApi =
|
const shahkarError = responseData as {
|
||||||
isResponseObject &&
|
requires_shahkar_verification?: boolean;
|
||||||
"requires_shahkar_verification" in responseData &&
|
result?: { requires_shahkar_verification?: boolean };
|
||||||
Boolean(
|
} | undefined;
|
||||||
(responseData as { requires_shahkar_verification?: boolean })
|
const requiresShahkarVerificationFromApi = Boolean(
|
||||||
.requires_shahkar_verification
|
shahkarError?.requires_shahkar_verification ||
|
||||||
|
shahkarError?.result?.requires_shahkar_verification
|
||||||
);
|
);
|
||||||
|
|
||||||
if (requiresShahkarVerificationFromApi) {
|
if (requiresShahkarVerificationFromApi) {
|
||||||
@@ -382,7 +390,7 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
|||||||
{advancedVerificationMessage}
|
{advancedVerificationMessage}
|
||||||
</Alert>
|
</Alert>
|
||||||
)}
|
)}
|
||||||
{needsShahkarVerification && (
|
{needsShahkarVerification && !identityVerified && (
|
||||||
<div className="w-full flex flex-col gap-2">
|
<div className="w-full flex flex-col gap-2">
|
||||||
<Alert type="warning" extra="!mb-0 text-start">
|
<Alert type="warning" extra="!mb-0 text-start">
|
||||||
برای خریدهای با مبلغ بالا، احراز هویت شاهکار (تطبیق شماره
|
برای خریدهای با مبلغ بالا، احراز هویت شاهکار (تطبیق شماره
|
||||||
|
|||||||
2
src/types/props.d.ts
vendored
2
src/types/props.d.ts
vendored
@@ -219,6 +219,8 @@ type UserProfile = {
|
|||||||
email: string;
|
email: string;
|
||||||
mobile: string;
|
mobile: string;
|
||||||
national_id?: string | null;
|
national_id?: string | null;
|
||||||
|
is_identity_verified?: boolean;
|
||||||
|
shahkar_verified_at?: string | null;
|
||||||
card_number?: string | null;
|
card_number?: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user