You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
434 lines
14 KiB
434 lines
14 KiB
"use client";
|
|
|
|
import Image from "next/image";
|
|
import { useRouter } from "next/navigation";
|
|
import { useEffect, useMemo, useState } from "react";
|
|
import Button from "@/components/ui/button";
|
|
import DismissReasonSheet from "@/components/ui/dismiss-reason-sheet";
|
|
import FemaleConsentSheet from "@/components/ui/female-consent-sheet";
|
|
import InformationSheet from "@/components/ui/information-sheet";
|
|
import NavigationButton from "@/components/ui/navigation-button";
|
|
import StickyHeader from "@/components/ui/sticky-header";
|
|
import { PageBackground } from "@/components/utils/page-background";
|
|
import type {
|
|
MarriageCaseStatus,
|
|
MarriageField,
|
|
MarriageFieldValue,
|
|
MarriageGender,
|
|
MarriagePhoneFieldValue,
|
|
} from "@/hooks/marriage/types";
|
|
import { useRespondToMarriageCaseMutation } from "@/hooks/marriage/use-case-respond";
|
|
import { useMarriageProfileQuery } from "@/hooks/marriage/use-profile-main";
|
|
import { getSubmitPath } from "@/lib/get-submit-path";
|
|
import { localizePath } from "@/translations/config";
|
|
import { useI18n } from "@/translations/provider";
|
|
|
|
function formatFieldValue(value: MarriageFieldValue) {
|
|
if (value === null || value === "") {
|
|
return null;
|
|
}
|
|
|
|
if (isMarriagePhoneFieldValue(value)) {
|
|
return `+${value.countryCode}${value.phoneNumber}`;
|
|
}
|
|
|
|
if (typeof value === "boolean") {
|
|
return value ? "Yes" : "No";
|
|
}
|
|
|
|
return String(value);
|
|
}
|
|
|
|
function isMarriagePhoneFieldValue(
|
|
value: unknown,
|
|
): value is MarriagePhoneFieldValue {
|
|
if (!value || typeof value !== "object") {
|
|
return false;
|
|
}
|
|
|
|
const phoneValue = value as Partial<MarriagePhoneFieldValue>;
|
|
|
|
return (
|
|
typeof phoneValue.countryCode === "string" &&
|
|
typeof phoneValue.phoneNumber === "string"
|
|
);
|
|
}
|
|
|
|
function titleFromKey(key: string) {
|
|
return key
|
|
.replace(/^q\d+[_-]?/i, "")
|
|
.replace(/[_-]+/g, " ")
|
|
.replace(/\s+/g, " ")
|
|
.trim()
|
|
.replace(/\b\w/g, (letter) => letter.toUpperCase());
|
|
}
|
|
|
|
function isImageField(field: MarriageField) {
|
|
return /(avatar|image|photo|picture|portrait|upload)/i.test(
|
|
`${field.key} ${field.label}`,
|
|
);
|
|
}
|
|
|
|
function canAcceptProfile(
|
|
gender: MarriageGender | null | undefined,
|
|
status: MarriageCaseStatus | null | undefined,
|
|
) {
|
|
if (!gender || !status) {
|
|
return false;
|
|
}
|
|
|
|
if (gender === "female") {
|
|
return status === "introduced" || status === "male_accepted";
|
|
}
|
|
|
|
return status === "introduced";
|
|
}
|
|
|
|
function MatchField({ field }: { field: MarriageField }) {
|
|
const value = formatFieldValue(field.value);
|
|
|
|
if (!value || isImageField(field)) {
|
|
return null;
|
|
}
|
|
|
|
const label = field.label || titleFromKey(field.key);
|
|
|
|
return (
|
|
<div className="mb-3 space-y-1 border-b border-[#000000]/08 pb-2.5 text-left">
|
|
<p className="text-[11px] font-semibold text-[#8E8E93]">{label}</p>
|
|
<p className="group-14 font-semibold text-[#1C1C1E]">{value}</p>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function MatchPublicProfileFields({
|
|
publicInfo,
|
|
}: {
|
|
publicInfo: MarriageField[] | null | undefined;
|
|
}) {
|
|
const visibleFields = useMemo(() => {
|
|
if (!publicInfo) return [];
|
|
return publicInfo.filter((field) => {
|
|
if (field.value === null || field.value === "" || isImageField(field)) {
|
|
return false;
|
|
}
|
|
if ((field as any).private === true) {
|
|
return false;
|
|
}
|
|
return true;
|
|
});
|
|
}, [publicInfo]);
|
|
|
|
if (!visibleFields.length) {
|
|
return (
|
|
<div className="mt-6 rounded-[16px] bg-white/70 p-5 text-center shadow-xs">
|
|
<p className="group-12 font-medium text-[#747474]">
|
|
اطلاعات عمومی قابل نمایشی ثبت نشده است.
|
|
</p>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="mt-6 space-y-3 rounded-[18px] bg-white/80 p-4 shadow-xs">
|
|
<h3 className="border-b border-[#F0445B]/15 pb-2 text-right group-12 font-bold text-[#F0445B]">
|
|
اطلاعات عمومی و مشخصات فردی
|
|
</h3>
|
|
<div className="space-y-2.5">
|
|
{visibleFields.map((field) => (
|
|
<MatchField key={field.key} field={field} />
|
|
))}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default function NewMatchProfilePage() {
|
|
const { dictionary: t, locale } = useI18n();
|
|
const router = useRouter();
|
|
const [isRequestSheetOpen, setIsRequestSheetOpen] = useState(false);
|
|
const [isFemaleConsentChecked, setIsFemaleConsentChecked] = useState(false);
|
|
const [isRejectSheetOpen, setIsRejectSheetOpen] = useState(false);
|
|
const [isDismissReasonSheetOpen, setIsDismissReasonSheetOpen] =
|
|
useState(false);
|
|
const { data: profile, refetch: refetchProfile } = useMarriageProfileQuery();
|
|
|
|
useEffect(() => {
|
|
if (!profile) {
|
|
return;
|
|
}
|
|
const targetPath = getSubmitPath(profile);
|
|
if (targetPath !== "/new-match") {
|
|
router.replace(localizePath(targetPath, locale));
|
|
}
|
|
}, [profile, locale, router]);
|
|
|
|
const caseId = profile?.active_case?.case_id;
|
|
const caseStatus = profile?.active_case?.status;
|
|
const isFemaleProfile = profile?.gender === "female";
|
|
const isMaleAccepted = caseStatus === "male_accepted";
|
|
const respondMutation = useRespondToMarriageCaseMutation(caseId ?? "", {
|
|
onSuccess: async (_, variables) => {
|
|
if (variables.action === "accept") {
|
|
const { data: updatedProfile } = await refetchProfile();
|
|
const nextPath = getSubmitPath(updatedProfile);
|
|
router.replace(localizePath(nextPath, locale));
|
|
return;
|
|
}
|
|
|
|
router.replace(localizePath("/finding-match", locale));
|
|
},
|
|
});
|
|
|
|
const candidateName = useMemo(() => {
|
|
const publicInfo = profile?.match_summary?.public_info ?? [];
|
|
const nameField = publicInfo.find(
|
|
(f) =>
|
|
f.key === "q1_full_name" ||
|
|
f.key.toLowerCase().includes("name") ||
|
|
f.key.toLowerCase().includes("nam") ||
|
|
f.label.includes("نام"),
|
|
);
|
|
const formatted = formatFieldValue(nameField?.value ?? null);
|
|
if (formatted) return formatted;
|
|
const firstVal = publicInfo.find((f) => Boolean(f.value))?.value ?? null;
|
|
return formatFieldValue(firstVal) || "نامشخص";
|
|
}, [profile?.match_summary?.public_info]);
|
|
|
|
const isSubmitting = respondMutation.isPending;
|
|
const isAcceptProfileEnabled =
|
|
Boolean(caseId) &&
|
|
!isSubmitting &&
|
|
canAcceptProfile(profile?.gender, caseStatus);
|
|
|
|
return (
|
|
<>
|
|
<PageBackground />
|
|
{isRequestSheetOpen ? (
|
|
isFemaleProfile ? (
|
|
<FemaleConsentSheet
|
|
title="Final Confirmation & Consent"
|
|
description="By approving this profile, the male candidate will be notified to proceed with acquiring your contact information for further communication. Please ensure full family alignment before proceeding"
|
|
buttons={({ close }) => (
|
|
<div className="space-y-5">
|
|
<button
|
|
type="button"
|
|
onClick={() => setIsFemaleConsentChecked((value) => !value)}
|
|
className="flex w-full items-start gap-4 rounded-[15px] border-2 border-white bg-white/50 px-5 py-5 text-left shadow-[0_8px_24px_rgba(0,0,0,0.05)]"
|
|
>
|
|
<span
|
|
className={[
|
|
"mt-1 flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded-full border-1",
|
|
isFemaleConsentChecked
|
|
? "border-[#F0445B] bg-[#F0445B]"
|
|
: "border-[#2B2B2B] bg-white",
|
|
].join(" ")}
|
|
aria-hidden="true"
|
|
>
|
|
{isFemaleConsentChecked ? (
|
|
<span className="h-3 w-3 rounded-full bg-[#F0445B]" />
|
|
) : null}
|
|
</span>
|
|
<span className="text-xs leading-[1.35] text-[#3F3F3F]">
|
|
I confirm that the female candidate and her family have
|
|
reviewed this profile and tentatively agree to further
|
|
communication
|
|
</span>
|
|
</button>
|
|
|
|
<div className="grid w-full grid-cols-2 gap-3">
|
|
<Button
|
|
variant="outlined"
|
|
className="py-[18px] text-[18px]"
|
|
onClick={close}
|
|
>
|
|
{t.common.cancel}
|
|
</Button>
|
|
<Button
|
|
className="py-[18px] text-[18px]"
|
|
disabled={
|
|
!caseId ||
|
|
isSubmitting ||
|
|
!isAcceptProfileEnabled ||
|
|
!isFemaleConsentChecked
|
|
}
|
|
onClick={async () => {
|
|
close();
|
|
if (!isAcceptProfileEnabled) {
|
|
return;
|
|
}
|
|
|
|
await respondMutation.mutateAsync({ action: "accept" });
|
|
}}
|
|
>
|
|
{t.common.confirm}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
)}
|
|
onClose={() => {
|
|
setIsFemaleConsentChecked(false);
|
|
setIsRequestSheetOpen(false);
|
|
}}
|
|
/>
|
|
) : (
|
|
<InformationSheet
|
|
icon="check"
|
|
title="Request to Proceed"
|
|
description="With your approval, we will approach their family on your behalf to propose marriage. After their family agrees, you will be introduced to each other for further acquaintance."
|
|
buttons={({ close }) => (
|
|
<div className="grid w-full grid-cols-2 gap-3">
|
|
<Button
|
|
variant="outlined"
|
|
className="py-[18px]"
|
|
onClick={close}
|
|
>
|
|
{t.common.cancel}
|
|
</Button>
|
|
<Button
|
|
className="py-[18px]"
|
|
disabled={!isAcceptProfileEnabled}
|
|
onClick={async () => {
|
|
close();
|
|
if (!isAcceptProfileEnabled) {
|
|
return;
|
|
}
|
|
|
|
await respondMutation.mutateAsync({ action: "accept" });
|
|
}}
|
|
>
|
|
{t.common.confirm}
|
|
</Button>
|
|
</div>
|
|
)}
|
|
onClose={() => setIsRequestSheetOpen(false)}
|
|
/>
|
|
)
|
|
) : null}
|
|
{isRejectSheetOpen ? (
|
|
<InformationSheet
|
|
icon="warning"
|
|
title="Reject Profile"
|
|
description="Are you sure you've fully reviewed the profile and want to reject this profile?"
|
|
buttons={({ close }) => (
|
|
<div className="grid w-full grid-cols-2 gap-3">
|
|
<Button variant="outlined" className="py-[18px]" onClick={close}>
|
|
{t.common.cancel}
|
|
</Button>
|
|
<Button
|
|
className="py-[18px]"
|
|
onClick={() => {
|
|
close();
|
|
setIsDismissReasonSheetOpen(true);
|
|
}}
|
|
>
|
|
Reject
|
|
</Button>
|
|
</div>
|
|
)}
|
|
onClose={() => setIsRejectSheetOpen(false)}
|
|
/>
|
|
) : null}
|
|
{isDismissReasonSheetOpen ? (
|
|
<DismissReasonSheet
|
|
onClose={() => setIsDismissReasonSheetOpen(false)}
|
|
onSubmit={async (reason) => {
|
|
if (!caseId) {
|
|
return;
|
|
}
|
|
|
|
await respondMutation.mutateAsync({
|
|
action: "reject",
|
|
custom_note: reason,
|
|
});
|
|
}}
|
|
/>
|
|
) : null}
|
|
|
|
<main className="-mx-[17px] flex min-h-screen flex-col bg-[linear-gradient(180deg,rgba(255,197,196,0.2)_0%,rgba(251,237,237,0.7)_100%)] pb-10">
|
|
<StickyHeader>
|
|
<div className="flex items-center justify-between gap-3">
|
|
<NavigationButton
|
|
variant="transparent"
|
|
icon="close"
|
|
iconLabel={t.match.goBack}
|
|
/>
|
|
<h1 className="min-w-0 flex-1 text-center group-16 font-bold text-white">
|
|
{t.match.title}
|
|
</h1>
|
|
<div className="size-10 shrink-0" />
|
|
</div>
|
|
</StickyHeader>
|
|
|
|
<section className="px-[17px] pb-32 pt-5">
|
|
<div>
|
|
<Image
|
|
src={"/assets/images/Group 1597880481.png"}
|
|
alt=""
|
|
width={90}
|
|
height={90}
|
|
className="rounded-full"
|
|
/>
|
|
<div className="relative inline-block mt-2">
|
|
<p
|
|
className="text-[25px] leading-none text-white/80"
|
|
style={{ letterSpacing: "-2.3px", fontWeight: "1000" }}
|
|
>
|
|
{candidateName}
|
|
</p>
|
|
<p className="absolute inset-0 whitespace-nowrap text-[22px] font-bold leading-none text-[#F0445B]">
|
|
{candidateName}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<MatchPublicProfileFields
|
|
publicInfo={profile?.match_summary?.public_info}
|
|
/>
|
|
</section>
|
|
|
|
<div
|
|
style={{ paddingBottom: `var(--safe-bottom)` }}
|
|
className="fixed inset-x-0 bottom-0 z-30 px-[17px]"
|
|
>
|
|
<div className="mx-auto w-full sm:max-w-[375px] rounded-t-[24px] bg-white px-4 py-4 shadow-[0_12px_30px_rgba(0,0,0,0.14)]">
|
|
<div className="flex gap-3">
|
|
<button
|
|
type="button"
|
|
disabled={!caseId || isSubmitting || isMaleAccepted}
|
|
onClick={() => setIsRejectSheetOpen(true)}
|
|
className="inline-flex w-1/3 items-center justify-center rounded-[12px] border border-[#BFBFBF] bg-white px-4 py-[13px] text-[16px] font-semibold text-[#9A9A9A]"
|
|
>
|
|
Reject
|
|
</button>
|
|
<button
|
|
type="button"
|
|
disabled={!isAcceptProfileEnabled}
|
|
onClick={() => {
|
|
if (!isAcceptProfileEnabled) {
|
|
return;
|
|
}
|
|
|
|
if (isFemaleProfile) {
|
|
setIsFemaleConsentChecked(false);
|
|
}
|
|
|
|
setIsRequestSheetOpen(true);
|
|
}}
|
|
className="inline-flex w-2/3 whitespace-nowrap items-center justify-center gap-1 rounded-[12px] bg-[#F0445B] px-4 py-[13px] text-[16px] font-semibold text-white shadow-[0_8px_16px_rgba(240,68,91,0.24)] disabled:cursor-not-allowed disabled:opacity-50"
|
|
>
|
|
<Image
|
|
src="/assets/images/Icfdason.svg"
|
|
alt=""
|
|
width={28}
|
|
height={28}
|
|
/>
|
|
<span>{t.match.acceptProfile}</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
</>
|
|
);
|
|
}
|