mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-10-31 18:19:43 +00:00
fix(mobile): preserve joined invites on cancellation
This commit is contained in:
1 parent
a1b62c3b47
commit
8e48467414
2 files changed
+36
-11
No files matched your search
@@ -31,7 +31,7 @@ export default function PairedScreen() {
|
|||||||
if (heading.current) AccessibilityInfo.setAccessibilityFocus(heading.current as never);
|
if (heading.current) AccessibilityInfo.setAccessibilityFocus(heading.current as never);
|
||||||
}, 250);
|
}, 250);
|
||||||
return () => clearTimeout(timer);
|
return () => clearTimeout(timer);
|
||||||
}, [ready, user, couple, newMatchesCount]);
|
}, [ready, error, user, couple, newMatchesCount]);
|
||||||
|
|
||||||
const partnerName = partner?.name?.split(" ")[0] || "your partner";
|
const partnerName = partner?.name?.split(" ")[0] || "your partner";
|
||||||
const viewMatches = () => { Events.pairingUnlockCtaTapped(role, "view_matches"); router.replace("/(app)/matches"); };
|
const viewMatches = () => { Events.pairingUnlockCtaTapped(role, "view_matches"); router.replace("/(app)/matches"); };
|
||||||
|
|||||||
@@ -242,6 +242,38 @@ export default function PairingScreen() {
|
|||||||
Events.codeShared();
|
Events.codeShared();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const completeJoinedInvite = async () => {
|
||||||
|
await fetchUser();
|
||||||
|
await fetchCouple();
|
||||||
|
await useMatchStore.getState().fetchMatches(true);
|
||||||
|
router.replace("/(app)/paired" as any);
|
||||||
|
};
|
||||||
|
|
||||||
|
const cancelInvite = async (afterCancel?: () => Promise<void>) => {
|
||||||
|
try {
|
||||||
|
await coupleApi.cancelInvite();
|
||||||
|
await fetchUser();
|
||||||
|
await fetchCouple();
|
||||||
|
if (afterCancel) await afterCancel();
|
||||||
|
Events.pairingCancelled();
|
||||||
|
return true;
|
||||||
|
} catch (error: any) {
|
||||||
|
const apiCode = error instanceof ApiError
|
||||||
|
? (error.details as { error?: { code?: string } } | undefined)?.error?.code
|
||||||
|
: undefined;
|
||||||
|
if (apiCode === "invite_already_joined") {
|
||||||
|
await completeJoinedInvite();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Alert.alert(
|
||||||
|
"Couldn't cancel invite",
|
||||||
|
"Your invite may still be active. Check your connection and try again.",
|
||||||
|
[{ text: "Not now", style: "cancel" }, { text: "Try again", onPress: () => { void cancelInvite(afterCancel); } }],
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const copyInviteLink = async () => {
|
const copyInviteLink = async () => {
|
||||||
if (couple?.invite_code) {
|
if (couple?.invite_code) {
|
||||||
await Clipboard.setStringAsync(`https://sauci.app/join/${couple.invite_code}`);
|
await Clipboard.setStringAsync(`https://sauci.app/join/${couple.invite_code}`);
|
||||||
@@ -260,13 +292,7 @@ export default function PairingScreen() {
|
|||||||
onPress: async () => {
|
onPress: async () => {
|
||||||
setIsSubmitting(true);
|
setIsSubmitting(true);
|
||||||
try {
|
try {
|
||||||
await coupleApi.cancel();
|
await cancelInvite();
|
||||||
|
|
||||||
await fetchUser();
|
|
||||||
await fetchCouple();
|
|
||||||
Events.pairingCancelled();
|
|
||||||
} catch (error: any) {
|
|
||||||
Alert.alert("Error", getPairingError(error));
|
|
||||||
} finally {
|
} finally {
|
||||||
setIsSubmitting(false);
|
setIsSubmitting(false);
|
||||||
}
|
}
|
||||||
@@ -291,12 +317,11 @@ export default function PairingScreen() {
|
|||||||
text: "Cancel mine and join", style: "destructive", onPress: async () => {
|
text: "Cancel mine and join", style: "destructive", onPress: async () => {
|
||||||
setIsSubmitting(true);
|
setIsSubmitting(true);
|
||||||
try {
|
try {
|
||||||
await coupleApi.cancel();
|
await cancelInvite(async () => {
|
||||||
await fetchUser();
|
|
||||||
await fetchCouple();
|
|
||||||
setInviteCode(incomingCode);
|
setInviteCode(incomingCode);
|
||||||
setWasPrefilled(true);
|
setWasPrefilled(true);
|
||||||
await clearPendingInviteCode();
|
await clearPendingInviteCode();
|
||||||
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setIsSubmitting(false);
|
setIsSubmitting(false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user