- {requestSentCopy.matchProfile}
+
+ {isOpeningProfile && isLoading ? (
+
+ ) : (
+ requestSentCopy.matchProfile
+ )}
diff --git a/src/data/countries.ts b/src/data/countries.ts
index b57bb62..dd02a39 100644
--- a/src/data/countries.ts
+++ b/src/data/countries.ts
@@ -5110,6 +5110,7 @@ export function resolveCountryName(
if (!trimmed) return "";
const isFa = String(locale || "en").toLowerCase().startsWith("fa");
+ const iso = getCountryIsoCode(trimmed);
// 1. If Persian locale, prioritize curated COUNTRIES_FA
if (isFa) {
@@ -5136,7 +5137,7 @@ export function resolveCountryName(
// 2. Dynamic Intl.DisplayNames for the requested locale
if (iso) {
try {
- const displayNames = new Intl.DisplayNames([isFa ? "fa" : "en"], {
+ const displayNames = new Intl.DisplayNames([locale], {
type: "region",
});
const name = displayNames.of(iso);
diff --git a/src/hooks/marriage/use-profile-main.ts b/src/hooks/marriage/use-profile-main.ts
index 7196011..4cd6f59 100644
--- a/src/hooks/marriage/use-profile-main.ts
+++ b/src/hooks/marriage/use-profile-main.ts
@@ -1,6 +1,8 @@
"use client";
-import { useQuery } from "@tanstack/react-query";
+import { useQuery, useQueryClient } from "@tanstack/react-query";
+import { useEffect } from "react";
+import { authBridge } from "@/lib/auth-bridge";
import { setCachedMarriageEntryPath } from "@/lib/entry-route-cache";
import {
getSubmitPath,
@@ -11,6 +13,27 @@ import type { QueryOptions } from "./options";
import { marriageQueryKeys } from "./query-keys";
import type { MarriageProfileResponse } from "./types";
+export function getInitialMarriageProfile(): MarriageProfileResponse | undefined {
+ const data = authBridge.getMarriageData();
+ if (!data) return undefined;
+
+ return {
+ id: data.id ?? 0,
+ status: data.status,
+ gender: data.gender,
+ age: data.age ?? null,
+ is_registering_for_self: data.is_registering_for_self ?? null,
+ can_edit_profile: data.can_edit_profile ?? true,
+ can_message_expert: data.can_message_expert ?? true,
+ active_subscription: data.active_subscription ?? null,
+ is_ready_for_match: data.is_ready_for_match ?? true,
+ active_case: data.active_case ?? null,
+ needs_subscription: data.needs_subscription ?? false,
+ recommended_plan: data.recommended_plan ?? null,
+ match_summary: data.match_summary ?? null,
+ } as MarriageProfileResponse;
+}
+
export async function getMarriageProfile() {
console.log("🌐 [Profile API] Sending GET /api/marriage/profile/main/ ...");
try {
@@ -44,9 +67,34 @@ export async function getMarriageProfile() {
export function useMarriageProfileQuery
(
options?: QueryOptions,
) {
+ const queryClient = useQueryClient();
+
+ useEffect(() => {
+ const handleInitialData = (e: Event) => {
+ const customEvent = e as CustomEvent;
+ const initial = getInitialMarriageProfile();
+ if (initial) {
+ queryClient.setQueryData(marriageQueryKeys.profile(), (old: any) => {
+ if (!old) return initial;
+ return {
+ ...old,
+ ...initial,
+ match_summary: initial.match_summary ?? old.match_summary,
+ };
+ });
+ }
+ };
+
+ window.addEventListener("habib:marriage-initial-data", handleInitialData);
+ return () => {
+ window.removeEventListener("habib:marriage-initial-data", handleInitialData);
+ };
+ }, [queryClient]);
+
const query = useQuery({
staleTime: 5 * 60 * 1000,
refetchOnWindowFocus: false,
+ initialData: getInitialMarriageProfile as any,
...options,
queryFn: getMarriageProfile,
queryKey: marriageQueryKeys.profile(),
diff --git a/src/lib/auth-bridge.ts b/src/lib/auth-bridge.ts
index 4bfc8a7..b698e60 100644
--- a/src/lib/auth-bridge.ts
+++ b/src/lib/auth-bridge.ts
@@ -23,6 +23,7 @@ function postFlutterMessage(payload: Record) {
class AuthBridge {
private token: string | null = null;
private coins = 0;
+ private marriageData: Record | null = null;
private isReady = false;
private loginRequested = false;
private readyCallbacks: Array<() => void> = [];
@@ -33,6 +34,10 @@ class AuthBridge {
this.init();
}
+ public getMarriageData(): Record | null {
+ return this.marriageData;
+ }
+
private syncFromStorage() {
if (typeof window === "undefined") {
return false;
@@ -41,8 +46,15 @@ class AuthBridge {
const win = window as Window & {
HABIB_TOKEN?: string;
HABIB_COINS?: number;
+ HABIB_MARRIAGE?: Record;
+ __HABIB_MARRIAGE_INITIAL_DATA__?: Record;
};
+ if (win.HABIB_MARRIAGE || win.__HABIB_MARRIAGE_INITIAL_DATA__) {
+ this.marriageData =
+ win.HABIB_MARRIAGE ?? win.__HABIB_MARRIAGE_INITIAL_DATA__ ?? null;
+ }
+
const token =
win.HABIB_TOKEN ??
getClientCookie(TOKEN_COOKIE_NAME) ??
@@ -88,6 +100,17 @@ class AuthBridge {
(event) => {
if (event.action === "login") {
this.handleLoginResponse(event.success);
+ } else if (
+ event.action === "initial_config" &&
+ event.data &&
+ (event.data as any).marriage
+ ) {
+ this.marriageData = (event.data as any).marriage;
+ window.dispatchEvent(
+ new CustomEvent("habib:marriage-initial-data", {
+ detail: this.marriageData,
+ }),
+ );
}
},
);