feat: opt auth established
This commit is contained in:
62
src/partials/tagging/OtpAuthModal.tsx
Normal file
62
src/partials/tagging/OtpAuthModal.tsx
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { Grid } from "../../components/Grid/Grid";
|
||||||
|
import Button from "../../components/Button/Button";
|
||||||
|
import AutoComplete from "../../components/AutoComplete/AutoComplete";
|
||||||
|
import { useApiMutation, useApiRequest } from "../../utils/useApiRequest";
|
||||||
|
import { useToast } from "../../hooks/useToast";
|
||||||
|
import { useModalStore } from "../../context/zustand-store/appStore";
|
||||||
|
|
||||||
|
export const OtpAuthModal = ({ item, getData }: any) => {
|
||||||
|
const showToast = useToast();
|
||||||
|
const { closeModal } = useModalStore();
|
||||||
|
const [selectedUser, setSelectedUser] = useState<(string | number)[]>([]);
|
||||||
|
|
||||||
|
const { data: usersData } = useApiRequest({
|
||||||
|
api: `/auth/api/v1/organization/${item?.id}/org_users/`,
|
||||||
|
method: "get",
|
||||||
|
queryKey: ["orgUsers", item?.id],
|
||||||
|
});
|
||||||
|
|
||||||
|
const mutation = useApiMutation({
|
||||||
|
api: `/tag/web/api/v1/tag_distribution_batch/${item?.id}/otp_auth/?otp_type=send`,
|
||||||
|
method: "post",
|
||||||
|
});
|
||||||
|
|
||||||
|
const usersOptions =
|
||||||
|
usersData?.results?.map((user: any) => ({
|
||||||
|
key: user?.user_receiver,
|
||||||
|
value: `${user?.first_name} ${user?.last_name} - ${user?.mobile}`,
|
||||||
|
})) ?? [];
|
||||||
|
|
||||||
|
const onSubmit = async () => {
|
||||||
|
if (selectedUser.length === 0) return;
|
||||||
|
|
||||||
|
const selected = usersData?.results?.find(
|
||||||
|
(u: any) => u.user_receiver === selectedUser[0],
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await mutation.mutateAsync(selected);
|
||||||
|
showToast("ارسال با موفقیت انجام شد", "success");
|
||||||
|
getData();
|
||||||
|
closeModal();
|
||||||
|
} catch (error: any) {
|
||||||
|
showToast(error?.response?.data?.message || "خطا در ارسال!", "error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Grid container column className="gap-3">
|
||||||
|
<AutoComplete
|
||||||
|
data={usersOptions}
|
||||||
|
selectedKeys={selectedUser}
|
||||||
|
onChange={(keys) => setSelectedUser(keys)}
|
||||||
|
title="انتخاب کاربر"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button disabled={selectedUser.length === 0} onClick={onSubmit}>
|
||||||
|
ارسال
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -23,6 +23,7 @@ import Table from "../../components/Table/Table";
|
|||||||
import { BooleanQuestion } from "../../components/BooleanQuestion/BooleanQuestion";
|
import { BooleanQuestion } from "../../components/BooleanQuestion/BooleanQuestion";
|
||||||
import { TableButton } from "../../components/TableButton/TableButton";
|
import { TableButton } from "../../components/TableButton/TableButton";
|
||||||
import { DistributionSpeciesModal } from "./DistributionSpeciesModal";
|
import { DistributionSpeciesModal } from "./DistributionSpeciesModal";
|
||||||
|
import { OtpAuthModal } from "./OtpAuthModal";
|
||||||
import { useNavigate } from "@tanstack/react-router";
|
import { useNavigate } from "@tanstack/react-router";
|
||||||
import { TAG_DISTRIBUTION } from "../../routes/paths";
|
import { TAG_DISTRIBUTION } from "../../routes/paths";
|
||||||
import { DocumentOperation } from "../../components/DocumentOperation/DocumentOperation";
|
import { DocumentOperation } from "../../components/DocumentOperation/DocumentOperation";
|
||||||
@@ -234,6 +235,18 @@ export default function TagActiveDistributions() {
|
|||||||
<XCircleIcon className="w-5 h-5" />
|
<XCircleIcon className="w-5 h-5" />
|
||||||
</span>
|
</span>
|
||||||
),
|
),
|
||||||
|
<Button
|
||||||
|
key={`otp-${item?.id}`}
|
||||||
|
size="small"
|
||||||
|
onClick={() => {
|
||||||
|
openModal({
|
||||||
|
title: "ارسال پیامک احراز",
|
||||||
|
content: <OtpAuthModal item={item} getData={handleUpdate} />,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
ارسال کد
|
||||||
|
</Button>,
|
||||||
<Popover key={index}>
|
<Popover key={index}>
|
||||||
<Tooltip title="جزئیات توزیع" position="right">
|
<Tooltip title="جزئیات توزیع" position="right">
|
||||||
<Button
|
<Button
|
||||||
@@ -404,6 +417,7 @@ export default function TagActiveDistributions() {
|
|||||||
"سند خروج از انبار",
|
"سند خروج از انبار",
|
||||||
"تایید سند خروج",
|
"تایید سند خروج",
|
||||||
"وضعیت احراز پیامکی",
|
"وضعیت احراز پیامکی",
|
||||||
|
"احراز پیامکی",
|
||||||
"عملیات",
|
"عملیات",
|
||||||
]}
|
]}
|
||||||
rows={tagsTableData}
|
rows={tagsTableData}
|
||||||
|
|||||||
Reference in New Issue
Block a user