feat(chat): add promotional external entry flow
This commit is contained in:
@@ -5,8 +5,14 @@ import { useRouter } from "next/navigation";
|
||||
|
||||
import {
|
||||
persistExternalEntryPayload,
|
||||
resolveExternalEntryPromotionType,
|
||||
resolveExternalEntryTarget,
|
||||
} from "@/lib/navigation/external_entry";
|
||||
import {
|
||||
clearPendingChatPromotion,
|
||||
savePendingChatPromotion,
|
||||
} from "@/lib/navigation/chat_unlock_session";
|
||||
import { ROUTES } from "@/router/routes";
|
||||
import { Logger } from "@/utils";
|
||||
|
||||
const log = new Logger("ExternalEntryPersist");
|
||||
@@ -17,8 +23,8 @@ interface ExternalEntryPersistProps {
|
||||
psid: string | null;
|
||||
avatarUrl: string | null;
|
||||
target: string | null;
|
||||
redirect: string | null;
|
||||
next: string | null;
|
||||
mode: string | null;
|
||||
promotionType: string | null;
|
||||
}
|
||||
|
||||
export default function ExternalEntryPersist({
|
||||
@@ -27,26 +33,31 @@ export default function ExternalEntryPersist({
|
||||
psid,
|
||||
avatarUrl,
|
||||
target,
|
||||
redirect,
|
||||
next,
|
||||
mode,
|
||||
promotionType,
|
||||
}: ExternalEntryPersistProps) {
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
const destination = resolveExternalEntryTarget({
|
||||
target,
|
||||
redirect,
|
||||
next,
|
||||
const destination = resolveExternalEntryTarget({ target });
|
||||
const resolvedPromotionType = resolveExternalEntryPromotionType({
|
||||
mode,
|
||||
promotionType,
|
||||
});
|
||||
|
||||
void (async () => {
|
||||
try {
|
||||
await persistExternalEntryPayload({
|
||||
deviceId,
|
||||
asid,
|
||||
psid,
|
||||
avatarUrl,
|
||||
});
|
||||
await Promise.all([
|
||||
persistExternalEntryPayload({
|
||||
deviceId,
|
||||
asid,
|
||||
psid,
|
||||
avatarUrl,
|
||||
}),
|
||||
destination === ROUTES.chat && resolvedPromotionType
|
||||
? savePendingChatPromotion(resolvedPromotionType)
|
||||
: clearPendingChatPromotion(),
|
||||
]);
|
||||
} catch (error) {
|
||||
log.warn("[ExternalEntryPersist] failed to persist payload", error);
|
||||
} finally {
|
||||
@@ -57,9 +68,9 @@ export default function ExternalEntryPersist({
|
||||
avatarUrl,
|
||||
asid,
|
||||
deviceId,
|
||||
next,
|
||||
mode,
|
||||
promotionType,
|
||||
psid,
|
||||
redirect,
|
||||
router,
|
||||
target,
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user