diff --git a/src/app/questions-list/page.tsx b/src/app/questions-list/page.tsx index 9fc7216..4c9a106 100644 --- a/src/app/questions-list/page.tsx +++ b/src/app/questions-list/page.tsx @@ -4,7 +4,10 @@ import Image from "next/image"; import { useRouter } from "next/navigation"; import { useEffect, useMemo, useState } from "react"; import { IoClose } from "react-icons/io5"; -import { getSubmitPath } from "@/lib/get-submit-path"; +import { + getSubmitPath, + hasCompletedMarriageProfileBasics, +} from "@/lib/get-submit-path"; import QuestionCard from "@/components/Componentes/question-card"; import RequiredStepsCard from "@/components/Componentes/required-steps-card"; import Button from "@/components/Componentes/button"; @@ -53,7 +56,9 @@ export default function QuestionsListPage() { [profile], ); const isProfileRedirecting = - profileTargetPath !== null && profileTargetPath !== "/questions-list"; + profileTargetPath !== null && + profileTargetPath !== "/questions-list" && + (!hasCompletedMarriageProfileBasics(profile) || profile?.can_edit_profile === false); useEffect(() => { if (isProfileRedirecting && profileTargetPath) { diff --git a/src/components/Componentes/token-switcher.tsx b/src/components/Componentes/token-switcher.tsx index 2d00828..e009067 100644 --- a/src/components/Componentes/token-switcher.tsx +++ b/src/components/Componentes/token-switcher.tsx @@ -2,12 +2,21 @@ import { useEffect, useState } from "react"; import { MdOutlineSwitchAccount } from "react-icons/md"; +import { + IoClose, + IoTrashOutline, + IoKeyOutline, +} from "react-icons/io5"; import { getClientCookie, setClientCookie } from "@/lib/cookies"; import { setCachedMarriageEntryPath } from "@/lib/entry-route-cache"; export const FEMALE_TOKEN = "545f61bb3e061ccb9b19f84715eb1b1ed4740331"; export const MALE_TOKEN = "f3a7543b44ef0a713d1ee0d4f7866b3825cf1308"; export const MALE_2_TOKEN = "56cd0fceb93f7cecf7ffa84c590135026cf54a1d"; +export const GUEST_MALE_1_TOKEN = "7490550734175c3935c54c808eba4933ee9c7633"; +export const GUEST_MALE_2_TOKEN = "88813b0434f2207582f515f2c38de0cafd517fb7"; +export const GUEST_FEMALE_1_TOKEN = "d9f0d61b2a7bbea89266eded6ad8d81a112f7ffe"; +export const GUEST_FEMALE_2_TOKEN = "da44906159958b3f071096160b509e1479ccbc1a"; export const FEMALE_EMAIL = "m.a.ghorbani01@gmail.com"; export const MALE_EMAIL = "muhammadamin.ghorbani@gmail.com"; @@ -27,7 +36,6 @@ export function TokenSwitcher({ const [isOpen, setIsOpen] = useState(false); const [currentToken, setCurrentToken] = useState(""); const [customTokenInput, setCustomTokenInput] = useState(""); - const [isCustomInputOpen, setIsCustomInputOpen] = useState(false); useEffect(() => { if (typeof window !== "undefined") { @@ -45,14 +53,21 @@ export function TokenSwitcher({ const isMale2 = currentToken === MALE_2_TOKEN; const isFemale = currentToken === FEMALE_TOKEN; const isNoToken = currentToken === "NO_TOKEN" || !currentToken; - const isCustomToken = !isMale && !isMale2 && !isFemale && !isNoToken; + const guestTokens = [ + GUEST_MALE_1_TOKEN, + GUEST_MALE_2_TOKEN, + GUEST_FEMALE_1_TOKEN, + GUEST_FEMALE_2_TOKEN, + ]; + const isGuestToken = guestTokens.includes(currentToken); + const isCustomToken = + !isMale && !isMale2 && !isFemale && !isNoToken && !isGuestToken; const handleSelectToken = (newToken: string) => { const trimmed = newToken.trim(); if (!trimmed) return; if (typeof window !== "undefined") { - // Clear local storage and session storage so answers and cached state from previous user are removed try { window.localStorage.clear(); window.sessionStorage.clear(); @@ -72,7 +87,6 @@ export function TokenSwitcher({ setCurrentToken(trimmed); setIsOpen(false); - // Navigate to the beginning of the flow (intro page) window.location.replace("/"); } }; @@ -88,7 +102,6 @@ export function TokenSwitcher({ } try { - // 1. Clear local storage and session storage completely if (typeof window !== "undefined") { try { window.localStorage.clear(); @@ -98,7 +111,6 @@ export function TokenSwitcher({ } } - // 2. Call backend reset script via API route if it is a real DB user if (userId !== null) { const response = await fetch("/api/dev-reset-profile", { method: "POST", @@ -115,7 +127,6 @@ export function TokenSwitcher({ } } - // 3. Set the target token in the cookies and redirect to / const targetToken = userId === 17119 ? MALE_TOKEN @@ -146,6 +157,64 @@ export function TokenSwitcher({ } }; + const mainAccounts = [ + { + id: 17119, + token: MALE_TOKEN, + title: "حساب آقا", + subtitle: MALE_EMAIL, + emoji: "👨", + isActive: isMale, + }, + { + id: 146024, + token: MALE_2_TOKEN, + title: "حساب آقا ۲", + subtitle: MALE_2_EMAIL, + emoji: "👨", + isActive: isMale2, + }, + { + id: 147714, + token: FEMALE_TOKEN, + title: "حساب خانم", + subtitle: FEMALE_EMAIL, + emoji: "👩", + isActive: isFemale, + }, + ]; + + const guestAccounts = [ + { + token: GUEST_MALE_1_TOKEN, + title: "حساب مهمان آقا ۱", + subtitle: "مهمان / بدون اطلاعات", + emoji: "👨", + isActive: currentToken === GUEST_MALE_1_TOKEN, + }, + { + token: GUEST_MALE_2_TOKEN, + title: "حساب مهمان آقا ۲", + subtitle: "مهمان / بدون اطلاعات", + emoji: "👨", + isActive: currentToken === GUEST_MALE_2_TOKEN, + }, + { + token: GUEST_FEMALE_1_TOKEN, + title: "حساب مهمان خانم ۱", + subtitle: "مهمان / بدون اطلاعات", + emoji: "👩", + isActive: currentToken === GUEST_FEMALE_1_TOKEN, + }, + { + token: GUEST_FEMALE_2_TOKEN, + title: "حساب مهمان خانم ۲", + subtitle: "مهمان / بدون اطلاعات", + emoji: "👩", + isActive: currentToken === GUEST_FEMALE_2_TOKEN, + }, + ]; + return ( <> -
- {/* Male option card */} -
- -
- {isMale && ( - - فعال - - )} - -
-
- {/* Male 2 option card */} -
-
- -
- {isMale2 && ( - - فعال - - )} -
-
+ ))} - {/* Female option card */} -
- -
- {isFemale && ( - - فعال - - )} - + +
+ {acc.isActive && ( + + فعال + + )} +
-
+ ))} - {/* Custom Token Card (if active) */} + {/* Custom Active Token Card (if any custom token is set) */} {isCustomToken && ( -
-
- 🔑 -
-
توکن سفارشی
-
+
+
+
+ 🔑 +
+
+ + توکن سفارشی + + {currentToken} -
+
-
- + +
+ فعال
)} - {/* No token option card */} + {/* No Token Option Card */}
- -
+
+ +
{isNoToken && ( - + فعال )} @@ -384,18 +454,18 @@ export function TokenSwitcher({ type="button" onClick={() => handleResetUser(null, "کاربر بدون توکن")} title="پاک کردن اطلاعات و شروع مجدد" - className="p-2 text-slate-400 hover:text-rose-500 hover:bg-rose-50 dark:hover:bg-rose-950/20 rounded-lg transition-colors" + className="size-8 rounded-lg flex items-center justify-center text-slate-400 hover:text-rose-600 hover:bg-rose-50 dark:hover:bg-rose-950/40 transition-colors cursor-pointer" > - 🗑️ +
- {/* Inline Custom Token Input Box */} -
-
- 🔑 - افزودن / تنظیم توکن دلخواه: + {/* Custom Token Input Section */} +
+
+ + افزودن یا تنظیم توکن دلخواه:
setCustomTokenInput(e.target.value)} placeholder="توکن ۳۲/۴۰ کاراکتری..." dir="ltr" - className="flex-1 rounded-lg border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-900 px-2.5 py-1.5 text-xs font-mono text-slate-800 dark:text-slate-200 outline-none focus:border-rose-500 transition-colors" + className="flex-1 min-w-0 rounded-xl border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-900 px-3 py-2 text-xs font-mono text-slate-800 dark:text-slate-200 outline-none focus:border-rose-500 focus:ring-1 focus:ring-rose-500/20 transition-all placeholder:text-slate-400 placeholder:text-[11px]" onKeyDown={(e) => { if (e.key === "Enter" && customTokenInput.trim()) { handleSelectToken(customTokenInput); @@ -415,7 +485,7 @@ export function TokenSwitcher({ type="button" disabled={!customTokenInput.trim()} onClick={() => handleSelectToken(customTokenInput)} - className="rounded-lg bg-rose-500 px-3 py-1.5 text-xs font-semibold text-white shadow-xs hover:bg-rose-600 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0" + className="rounded-xl bg-rose-500 hover:bg-rose-600 active:scale-95 px-4 py-2 text-xs font-bold text-white shadow-xs disabled:opacity-40 disabled:cursor-not-allowed transition-all shrink-0 cursor-pointer" > اعمال @@ -423,13 +493,14 @@ export function TokenSwitcher({
-
+ {/* Modal Footer */} +