diff --git a/src/partials/management/AddOrganization.tsx b/src/partials/management/AddOrganization.tsx
index 2a6daa4..b34be52 100644
--- a/src/partials/management/AddOrganization.tsx
+++ b/src/partials/management/AddOrganization.tsx
@@ -20,7 +20,13 @@ import { getToastResponse } from "../../data/getToastResponse";
import { useUserProfileStore } from "../../context/zustand-store/userStore";
import { useState } from "react";
import Checkbox from "../../components/CheckBox/CheckBox";
-import { PlusIcon, TrashIcon } from "@heroicons/react/24/outline";
+import {
+ ArrowPathIcon,
+ CheckBadgeIcon,
+ PlusIcon,
+ TrashIcon,
+} from "@heroicons/react/24/outline";
+import axios from "axios";
const schema = z.object({
name: zValidateString("نام سازمان"),
@@ -106,6 +112,10 @@ export const AddOrganization = ({ getData, item }: AddPageProps) => {
: [{ postal_code: "", address: "" }],
);
+ const [isInquiryRequired, setIsInquiryRequired] = useState(false);
+ const [inquiryPassed, setInquiryPassed] = useState(false);
+ const [inquiryLoading, setInquiryLoading] = useState(false);
+
const handleAddAddress = () => {
setAddresses((prev) => [...prev, { postal_code: "", address: "" }]);
};
@@ -124,7 +134,40 @@ export const AddOrganization = ({ getData, item }: AddPageProps) => {
);
};
+ const handleInquiry = async () => {
+ const code = getValues("unique_unit_identity");
+ if (!code) {
+ showToast("لطفاً شناسه یکتا واحد را وارد کنید!", "error");
+ return;
+ }
+ setInquiryLoading(true);
+ try {
+ await axios.get(
+ `https://rsibackend.rasadyar.com/app/has_code_in_db/?code=${code}`,
+ );
+ setInquiryPassed(true);
+ showToast("استعلام با موفقیت انجام شد!", "success");
+ } catch (error: any) {
+ if (error?.response?.status === 404) {
+ setInquiryPassed(false);
+ showToast("شناسه موجود نیست!", "error");
+ } else {
+ showToast("خطا در استعلام!", "error");
+ }
+ } finally {
+ setInquiryLoading(false);
+ }
+ };
+
const onSubmit = async (data: FormValues) => {
+ if (isInquiryRequired && !data.unique_unit_identity) {
+ showToast("شناسه یکتا واحد الزامی است!", "error");
+ return;
+ }
+ if (isInquiryRequired && !inquiryPassed) {
+ showToast("لطفاً ابتدا استعلام شناسه یکتا واحد را انجام دهید!", "error");
+ return;
+ }
try {
await mutation.mutateAsync({
addresses: addresses.filter(
@@ -187,6 +230,7 @@ export const AddOrganization = ({ getData, item }: AddPageProps) => {
keyField="id"
secondaryKey="is_repeatable"
tertiaryKey="org_type_field"
+ quaternaryKey="key"
valueField="name"
error={!!errors.organizationType}
errorMessage={errors.organizationType?.message}
@@ -197,6 +241,12 @@ export const AddOrganization = ({ getData, item }: AddPageProps) => {
trigger(["organizationType"]);
}}
onChangeValue={(r) => {
+ if (r.key4 === "U" || r.key4 === "CO") {
+ setIsInquiryRequired(true);
+ } else {
+ setIsInquiryRequired(false);
+ setInquiryPassed(false);
+ }
if (!r.key2) {
setValue("name", r.value);
} else {
@@ -261,14 +311,55 @@ export const AddOrganization = ({ getData, item }: AddPageProps) => {
name="unique_unit_identity"
control={control}
render={({ field }) => (
-