refactor(subscription): make return route and deep link parameters completely generic and dynamic (#12)
This commit is contained in:
parent
b22b6f05f1
commit
f3c3a3e8ac
|
|
@ -54,6 +54,8 @@ function resolveStorefrontUrl(): string {
|
||||||
return "http://localhost:3000";
|
return "http://localhost:3000";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DEFAULT_RETURN_ROUTE = "/modules";
|
||||||
|
|
||||||
export default function SubscriptionScreen() {
|
export default function SubscriptionScreen() {
|
||||||
const params = useLocalSearchParams();
|
const params = useLocalSearchParams();
|
||||||
const accessToken = useAuthStore((state) => state.accessToken);
|
const accessToken = useAuthStore((state) => state.accessToken);
|
||||||
|
|
@ -65,6 +67,7 @@ export default function SubscriptionScreen() {
|
||||||
const title = param(params.title) || "Clinical Module";
|
const title = param(params.title) || "Clinical Module";
|
||||||
const description = param(params.desc);
|
const description = param(params.desc);
|
||||||
const planCode = param(params.planCode).trim().toUpperCase();
|
const planCode = param(params.planCode).trim().toUpperCase();
|
||||||
|
const returnRoute = param(params.returnRoute) || param(params.returnTo) || DEFAULT_RETURN_ROUTE;
|
||||||
|
|
||||||
const [openingCheckout, setOpeningCheckout] = useState(false);
|
const [openingCheckout, setOpeningCheckout] = useState(false);
|
||||||
|
|
||||||
|
|
@ -84,16 +87,16 @@ export default function SubscriptionScreen() {
|
||||||
|
|
||||||
const handleBack = useCallback(() => {
|
const handleBack = useCallback(() => {
|
||||||
if (unlocked) {
|
if (unlocked) {
|
||||||
router.replace("/modules");
|
router.replace(returnRoute as never);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (router.canGoBack()) {
|
if (router.canGoBack()) {
|
||||||
router.back();
|
router.back();
|
||||||
} else {
|
} else {
|
||||||
router.replace("/modules");
|
router.replace(returnRoute as never);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}, [unlocked]);
|
}, [unlocked, returnRoute]);
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
|
|
@ -139,6 +142,13 @@ export default function SubscriptionScreen() {
|
||||||
if (apiUrl) query.set("apiUrl", apiUrl);
|
if (apiUrl) query.set("apiUrl", apiUrl);
|
||||||
if (moduleId) query.set("moduleId", moduleId);
|
if (moduleId) query.set("moduleId", moduleId);
|
||||||
if (moduleCode) query.set("moduleCode", moduleCode);
|
if (moduleCode) query.set("moduleCode", moduleCode);
|
||||||
|
const returnRouteClean = returnRoute.replace(/^\/+/, "");
|
||||||
|
if (returnRouteClean) query.set("returnRoute", returnRouteClean);
|
||||||
|
|
||||||
|
const appScheme = Array.isArray(Constants.expoConfig?.scheme)
|
||||||
|
? Constants.expoConfig?.scheme[0]
|
||||||
|
: Constants.expoConfig?.scheme;
|
||||||
|
if (appScheme) query.set("scheme", appScheme);
|
||||||
|
|
||||||
const checkoutUrl = `${storefrontUrl}?${query.toString()}`;
|
const checkoutUrl = `${storefrontUrl}?${query.toString()}`;
|
||||||
showAlert(
|
showAlert(
|
||||||
|
|
@ -206,7 +216,7 @@ export default function SubscriptionScreen() {
|
||||||
) : (
|
) : (
|
||||||
<PrimaryButton
|
<PrimaryButton
|
||||||
title="Back to Modules"
|
title="Back to Modules"
|
||||||
onPress={() => router.replace("/modules")}
|
onPress={() => router.replace(returnRoute as never)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue