Browse Source

refactor(ui): synchronize profile redirection with fetch status

Update client-side redirection logic across multiple routes to ensure
routing decisions are only made after the profile data has been
successfully fetched from the server. This prevents premature or
incorrect redirects based on stale or incomplete hydrated data.

- Add `isFetched` check to `useEffect` guards in candidate-contact,
  finding-match, new-match, request-accepted, and request-sent clients
- Update `QuestionsListClient` to wait for `isProfileFetched` before
  triggering redirects
- Clean up dependency arrays to include new fetch status variables
master
mortezaei 2 weeks ago
parent
commit
aa4214613c
  1. 4
      src/app/candidate-contact/candidate-contact-client.tsx
  2. 7
      src/app/finding-match/finding-match-client.tsx
  3. 9
      src/app/new-match/new-match-client.tsx
  4. 4
      src/app/questions-list/questions-list-client.tsx
  5. 5
      src/app/request-accepted/request-accepted-client.tsx
  6. 5
      src/app/request-sent/request-sent-client.tsx

4
src/app/candidate-contact/candidate-contact-client.tsx

@ -54,14 +54,14 @@ export default function CandidateContactClient() {
}); });
useEffect(() => { useEffect(() => {
if (!profile) {
if (!profile || !isFetched) {
return; return;
} }
const targetPath = getSubmitPath(profile); const targetPath = getSubmitPath(profile);
if (targetPath !== "/candidate-contact") { if (targetPath !== "/candidate-contact") {
router.replace(localizePath(targetPath, locale)); router.replace(localizePath(targetPath, locale));
} }
}, [profile, router, locale]);
}, [profile, isFetched, router, locale]);
// Signal Flutter to lift its loading cover immediately on mount // Signal Flutter to lift its loading cover immediately on mount
useHabibWebReady(true); useHabibWebReady(true);

7
src/app/finding-match/finding-match-client.tsx

@ -47,12 +47,7 @@ export default function FindingMatchClient() {
}); });
useEffect(() => { useEffect(() => {
if (!profile) {
return;
}
// Don't bounce away from finding-match if we only have preliminary initialData
// with pending_info before the fresh server query finishes
if (!isFetched && profile.status === "pending_info") {
if (!profile || !isFetched) {
return; return;
} }
const targetPath = getSubmitPath(profile); const targetPath = getSubmitPath(profile);

9
src/app/new-match/new-match-client.tsx

@ -597,19 +597,14 @@ export default function NewMatchClient() {
fullProfileObject: profile, fullProfileObject: profile,
}); });
if (!profile) {
return;
}
// Don't redirect based on stale native-injected initialData that may be
// missing active_case; wait for the first real server response.
if (!isFetched && profile.status === "in_case" && !profile.active_case) {
if (!profile || !isFetched) {
return; return;
} }
const targetPath = getSubmitPath(profile); const targetPath = getSubmitPath(profile);
if (targetPath !== "/new-match") { if (targetPath !== "/new-match") {
router.replace(localizePath(targetPath, locale)); router.replace(localizePath(targetPath, locale));
} }
}, [profile, locale, router, isLoading, isFetched, isError]);
}, [profile, locale, router, isFetched]);
// Signal Flutter to lift its loading cover immediately on mount // Signal Flutter to lift its loading cover immediately on mount
useHabibWebReady(true); useHabibWebReady(true);

4
src/app/questions-list/questions-list-client.tsx

@ -126,10 +126,10 @@ export default function QuestionsListClient() {
}, [profile, profileTargetPath]); }, [profile, profileTargetPath]);
useEffect(() => { useEffect(() => {
if (isProfileRedirecting && profileTargetPath) {
if (isProfileFetched && isProfileRedirecting && profileTargetPath) {
router.replace(localizePath(profileTargetPath, locale)); router.replace(localizePath(profileTargetPath, locale));
} }
}, [isProfileRedirecting, locale, profileTargetPath, router]);
}, [isProfileFetched, isProfileRedirecting, locale, profileTargetPath, router]);
// Background prefetch user's geo country code so phone question is pre-warmed // Background prefetch user's geo country code so phone question is pre-warmed
useEffect(() => { useEffect(() => {

5
src/app/request-accepted/request-accepted-client.tsx

@ -255,10 +255,7 @@ export default function RequestAcceptedClient() {
const contactSharedAtStr = profile?.active_case?.contact_shared_at; const contactSharedAtStr = profile?.active_case?.contact_shared_at;
useEffect(() => { useEffect(() => {
if (!profile || noContactReportedSuccess) {
return;
}
if (!isFetched && profile.status === "in_case" && !profile.active_case) {
if (!profile || !isFetched || noContactReportedSuccess) {
return; return;
} }
const targetPath = getSubmitPath(profile); const targetPath = getSubmitPath(profile);

5
src/app/request-sent/request-sent-client.tsx

@ -45,10 +45,7 @@ export default function RequestSentClient() {
}); });
useEffect(() => { useEffect(() => {
if (!profile) {
return;
}
if (!isFetched && profile.status === "in_case" && !profile.active_case) {
if (!profile || !isFetched) {
return; return;
} }
const targetPath = getSubmitPath(profile); const targetPath = getSubmitPath(profile);

Loading…
Cancel
Save