From 741385e28292017d2cde1cd7854b374e8837e48b Mon Sep 17 00:00:00 2001 From: wixarm Date: Sat, 21 Feb 2026 11:29:34 +0330 Subject: [PATCH] add: manual entering sms receiver user --- src/partials/tagging/OtpAuthModal.tsx | 158 +++++++++++++++++++++++--- 1 file changed, 142 insertions(+), 16 deletions(-) diff --git a/src/partials/tagging/OtpAuthModal.tsx b/src/partials/tagging/OtpAuthModal.tsx index 0f87e13..ac73288 100644 --- a/src/partials/tagging/OtpAuthModal.tsx +++ b/src/partials/tagging/OtpAuthModal.tsx @@ -2,14 +2,49 @@ import { useState } from "react"; import { Grid } from "../../components/Grid/Grid"; import Button from "../../components/Button/Button"; import AutoComplete from "../../components/AutoComplete/AutoComplete"; +import Textfield from "../../components/Textfeild/Textfeild"; +import Checkbox from "../../components/CheckBox/CheckBox"; import { useApiMutation, useApiRequest } from "../../utils/useApiRequest"; import { useToast } from "../../hooks/useToast"; import { useModalStore } from "../../context/zustand-store/appStore"; +import { z } from "zod"; +import { Controller, useForm } from "react-hook-form"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { + zValidateString, + zValidateMobile, + zValidateNationalCode, +} from "../../data/getFormTypeErrors"; + +const schema = z.object({ + first_name: zValidateString("نام"), + last_name: zValidateString("نام خانوادگی"), + mobile: zValidateMobile("موبایل"), + national_code: zValidateNationalCode("کد ملی"), +}); + +type FormValues = z.infer; export const OtpAuthModal = ({ item, getData }: any) => { const showToast = useToast(); const { closeModal } = useModalStore(); const [selectedUser, setSelectedUser] = useState<(string | number)[]>([]); + const [isManual, setIsManual] = useState(false); + + const { + control, + handleSubmit, + reset, + formState: { errors }, + } = useForm({ + resolver: zodResolver(schema), + defaultValues: { + first_name: "", + last_name: "", + mobile: "", + national_code: "", + }, + }); const { data: usersData } = useApiRequest({ api: `/auth/api/v1/organization/${item?.assigned_org?.id}/org_users/`, @@ -28,15 +63,9 @@ export const OtpAuthModal = ({ item, getData }: any) => { value: `${user?.first_name} ${user?.last_name} - ${user?.mobile}`, })) ?? []; - const onSubmit = async () => { - if (selectedUser.length === 0) return; - - const selected = usersData?.find( - (u: any) => u.user_receiver === selectedUser[0], - ); - + const submitPayload = async (payload: any) => { try { - await mutation.mutateAsync(selected); + await mutation.mutateAsync(payload); showToast("ارسال با موفقیت انجام شد", "success"); getData(); closeModal(); @@ -45,18 +74,115 @@ export const OtpAuthModal = ({ item, getData }: any) => { } }; + const onManualSubmit = async (data: FormValues) => { + await submitPayload(data); + }; + + const onAutoCompleteSubmit = async () => { + if (selectedUser.length === 0) return; + const selected = usersData?.find( + (u: any) => u.user_receiver === selectedUser[0], + ); + await submitPayload(selected); + }; + return ( - setSelectedUser(keys)} - title="انتخاب کاربر" + { + setIsManual(e.target.checked); + setSelectedUser([]); + reset(); + }} /> - + {isManual ? ( +
+ + ( + + )} + /> + + ( + + )} + /> + + ( + + )} + /> + + ( + + )} + /> + + + +
+ ) : ( + <> + setSelectedUser(keys)} + title="انتخاب کاربر" + /> + + + + )}
); };