2026-01-18 14:32:49 +03:30
|
|
|
import * as yup from "yup";
|
|
|
|
|
import { normalizeDatabaseDate } from "./dateUtils";
|
|
|
|
|
|
|
|
|
|
export const getValidationSchema = (isEditMode) =>
|
|
|
|
|
yup.object({
|
|
|
|
|
national_id: yup
|
|
|
|
|
.string()
|
|
|
|
|
.required("کد ملی الزامی است")
|
|
|
|
|
.matches(/^[0-9]{10}$/, "کد ملی باید 10 رقم باشد"),
|
|
|
|
|
mobile: isEditMode
|
|
|
|
|
? yup
|
|
|
|
|
.string()
|
|
|
|
|
.nullable()
|
|
|
|
|
.test(
|
|
|
|
|
"mobile-format",
|
|
|
|
|
"شماره تلفن باید 11 رقم باشد",
|
|
|
|
|
(value) => !value || /^[0-9]{11}$/.test(value)
|
|
|
|
|
)
|
|
|
|
|
: yup
|
|
|
|
|
.string()
|
|
|
|
|
.required("شماره تلفن الزامی است")
|
|
|
|
|
.matches(/^[0-9]{11}$/, "شماره تلفن باید 11 رقم باشد"),
|
|
|
|
|
first_name: yup.string(),
|
|
|
|
|
last_name: yup.string(),
|
|
|
|
|
guild_name: yup.string(),
|
|
|
|
|
guild_category: yup.string(),
|
|
|
|
|
state: yup.string(),
|
|
|
|
|
city: yup.string(),
|
|
|
|
|
address: yup.string(),
|
|
|
|
|
license_expire_date: yup.string(),
|
|
|
|
|
license_status: yup.string(),
|
|
|
|
|
union_name: yup.string(),
|
|
|
|
|
postal_code: yup.string(),
|
|
|
|
|
guild_national_id: yup.string(),
|
|
|
|
|
is_foreigner: yup.string(),
|
|
|
|
|
national_code: yup.string(),
|
|
|
|
|
has_steward: yup.string(),
|
|
|
|
|
has_partner: yup.string(),
|
|
|
|
|
license_number: yup.string(),
|
|
|
|
|
isAccepted: yup
|
|
|
|
|
.boolean()
|
|
|
|
|
.test("req", "باید تعهد نامه را بپذیرید!", (val) => {
|
|
|
|
|
return val === true;
|
|
|
|
|
})
|
|
|
|
|
.required("این فیلد اجباری است!"),
|
2026-01-26 15:22:33 +03:30
|
|
|
guilds: yup
|
|
|
|
|
.array()
|
|
|
|
|
.min(1, "حداقل یک واحد صنفی باید وجود داشته باشد")
|
|
|
|
|
.of(
|
|
|
|
|
yup.object({
|
|
|
|
|
steward: yup.boolean().default(false),
|
|
|
|
|
guild: yup.boolean().default(false),
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
.test(
|
|
|
|
|
"steward-guild-required",
|
|
|
|
|
"برای هر واحد صنفی، حداقل یکی از گزینههای مباشر یا صنف باید انتخاب شود",
|
|
|
|
|
function (guilds) {
|
|
|
|
|
if (!guilds || guilds.length === 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return guilds.every(
|
|
|
|
|
(guild) => guild?.steward === true || guild?.guild === true
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
),
|
2026-01-18 14:32:49 +03:30
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const getInitialValues = (guild) => ({
|
|
|
|
|
first_name: guild?.user?.firstName || "",
|
|
|
|
|
last_name: guild?.user?.lastName || "",
|
|
|
|
|
corporation_name: guild?.companyName || "",
|
|
|
|
|
national_id: guild?.user?.nationalId || "",
|
|
|
|
|
national_code: guild?.user?.nationalCode || "",
|
|
|
|
|
birth_date: normalizeDatabaseDate(guild?.user?.birthday || ""),
|
|
|
|
|
father_name: guild?.user?.fatherName || "",
|
|
|
|
|
gender: guild?.user?.gender || "",
|
|
|
|
|
person_city: guild?.user?.city || "",
|
|
|
|
|
is_alive: guild?.user?.isAlive || "",
|
2026-01-26 15:22:33 +03:30
|
|
|
guild_name: guild?.guildsName || guild?.name || "",
|
2026-01-18 14:32:49 +03:30
|
|
|
area_activity: guild?.areaActivity || "",
|
|
|
|
|
state: guild?.address?.province?.name || "",
|
2026-01-26 15:22:33 +03:30
|
|
|
province: guild?.address?.province?.key || "",
|
|
|
|
|
city_name: guild?.address?.city?.name || "",
|
2026-01-18 14:32:49 +03:30
|
|
|
address: guild?.address?.address || "",
|
|
|
|
|
license_expire_date: normalizeDatabaseDate(guild?.licenseExpireDate || ""),
|
|
|
|
|
license_status: guild?.licenseStatus || "",
|
|
|
|
|
license_type: guild?.licenseType || "",
|
|
|
|
|
union_name: guild?.unionName || "",
|
|
|
|
|
postal_code: guild?.address?.postalCode || "",
|
|
|
|
|
phone_number: guild?.phoneNumber || "",
|
|
|
|
|
mobile: guild?.user?.mobile || "",
|
|
|
|
|
is_foreigner: guild?.is_foreign_national || "",
|
|
|
|
|
has_steward: guild?.hasSteward || "",
|
|
|
|
|
has_partner: guild?.hasPartner || "",
|
|
|
|
|
license_number: guild?.licenseNumber || "",
|
|
|
|
|
isAccepted: guild?.provinceAcceptState === "accepted" || false,
|
|
|
|
|
steward:
|
|
|
|
|
typeof guild?.steward === "boolean"
|
|
|
|
|
? guild.steward
|
|
|
|
|
: typeof guild?.isSteward === "boolean"
|
|
|
|
|
? guild.isSteward
|
|
|
|
|
: false,
|
|
|
|
|
guild:
|
|
|
|
|
typeof guild?.guild === "boolean"
|
|
|
|
|
? guild.guild
|
|
|
|
|
: typeof guild?.isGuild === "boolean"
|
|
|
|
|
? guild.isGuild
|
|
|
|
|
: false,
|
|
|
|
|
verify_mobile: guild?.verifyMobile || false,
|
|
|
|
|
guild_national_id: guild?.nationalId || "",
|
|
|
|
|
license_issue_date: normalizeDatabaseDate(guild?.licenseIssueDate || ""),
|
|
|
|
|
company_name: guild?.companyName || "",
|
|
|
|
|
company_identifier: guild?.companyIdentifier || "",
|
|
|
|
|
type_activity_name: guild?.typeActivityName || "",
|
|
|
|
|
active: guild?.active ?? null,
|
2026-01-26 15:22:33 +03:30
|
|
|
guilds: guild
|
|
|
|
|
? [
|
|
|
|
|
{
|
|
|
|
|
steward:
|
|
|
|
|
typeof guild?.steward === "boolean"
|
|
|
|
|
? guild.steward
|
|
|
|
|
: typeof guild?.isSteward === "boolean"
|
|
|
|
|
? guild.isSteward
|
|
|
|
|
: false,
|
|
|
|
|
guild:
|
|
|
|
|
typeof guild?.guild === "boolean"
|
|
|
|
|
? guild.guild
|
|
|
|
|
: typeof guild?.isGuild === "boolean"
|
|
|
|
|
? guild.isGuild
|
|
|
|
|
: false,
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
: [],
|
2026-01-18 14:32:49 +03:30
|
|
|
});
|