@ -216,5 +216,75 @@
|
|||||||
},
|
},
|
||||||
"ActionFieldsForm": {
|
"ActionFieldsForm": {
|
||||||
"required_field": "This field is required"
|
"required_field": "This field is required"
|
||||||
|
},
|
||||||
|
"AdditionalPurchases": {
|
||||||
|
"caution": {
|
||||||
|
"title": "Caution!",
|
||||||
|
"description": "To prevent double charges please don`t close the page and don`t go back."
|
||||||
|
},
|
||||||
|
"add-consultant": {
|
||||||
|
"title": "More for you",
|
||||||
|
"exclusive_offer": "Exclusive offer recommended for you to achieve your goals faster",
|
||||||
|
"your_unique_consultation": "Your unique individual consultation",
|
||||||
|
"30-minute": "30-minute private consultation with an expert",
|
||||||
|
"unlock_profound": "Unlock profound insights into your personality, relationships, career trajectory, and life's pivotal moments through astrology, empowering you to make informed decisions and achieve greater fulfillment.",
|
||||||
|
"one_time_price_offer": "One time price offer: <price></price>",
|
||||||
|
"choose_from": "Choose from 80+ experts astrologers.",
|
||||||
|
"original_price": "Original price: {oldPrice} ",
|
||||||
|
"save": "Economisez {discount}%",
|
||||||
|
"get_my_consultation": "Get my consultation",
|
||||||
|
"skip_this_offer": "Skip this offer",
|
||||||
|
"payment_error": "Something went wrong. Please try again later."
|
||||||
|
},
|
||||||
|
"add-guides": {
|
||||||
|
"title": "Choose your sign-up offer 🔥",
|
||||||
|
"subtitle": "Available only now",
|
||||||
|
"description": "*You will be charged for the add-on services or offers selected at the time of purchase. This is a non-recuring payment.",
|
||||||
|
"button": "Get my copy",
|
||||||
|
"payment_error": "Something went wrong. Please try again later.",
|
||||||
|
"select_product_error": "Please select a product",
|
||||||
|
"skip_offer": "Skip offer",
|
||||||
|
|
||||||
|
"products": {
|
||||||
|
"main_ultra_pack": {
|
||||||
|
"title": "ULTRA PACK",
|
||||||
|
"discount": "{discount}% OFF",
|
||||||
|
"subtitle": "(3 in 1 + 2 secret bonus reading)",
|
||||||
|
"price": "<price></price> ( regular price <oldPrice></oldPrice> )",
|
||||||
|
"emoji": "star_struck.webp"
|
||||||
|
},
|
||||||
|
"main_numerology_analysis": {
|
||||||
|
"title": "NUMEROLOGY ANALYSIS",
|
||||||
|
"discount": "{discount}% OFF",
|
||||||
|
"price": "<price></price> ( was <oldPrice></oldPrice> )",
|
||||||
|
"emoji": "input_numbers.webp"
|
||||||
|
},
|
||||||
|
"main_tarot_reading": {
|
||||||
|
"title": "TAROT READING",
|
||||||
|
"discount": "{discount}% OFF",
|
||||||
|
"price": "<price></price> ( was <oldPrice></oldPrice> )",
|
||||||
|
"emoji": "sunset.webp"
|
||||||
|
},
|
||||||
|
"main_palmistry_guide": {
|
||||||
|
"title": "PALMISTRY GUIDE",
|
||||||
|
"discount": "{discount}% OFF",
|
||||||
|
"price": "<price></price> ( was <oldPrice></oldPrice> )",
|
||||||
|
"emoji": "rised_hand.webp"
|
||||||
|
},
|
||||||
|
"main_money_reading": {
|
||||||
|
"title": "MONEY READING",
|
||||||
|
"discount": "{discount}% OFF",
|
||||||
|
"price": "<price></price> ( was <oldPrice></oldPrice> )",
|
||||||
|
"emoji": "money.png"
|
||||||
|
},
|
||||||
|
"main_skip_offer": {
|
||||||
|
"title": "SKIP OFFER",
|
||||||
|
"discount": "{discount}% OFF",
|
||||||
|
"price": "<price></price> ( was <oldPrice></oldPrice> )",
|
||||||
|
"subtitle": "You are missing out on both readings",
|
||||||
|
"emoji": "rised_hand.webp"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
7
public/check-mark-1.svg
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<svg width="14" height="12" viewBox="0 0 60 46" fill="#066FDF"
|
||||||
|
style="display: block; width: 14px; height: 12px; color: rgb(106, 58, 162);" xmlns="http://www.w3.org/2000/svg"
|
||||||
|
class="sc-424b5a3f-12 knbDkO">
|
||||||
|
<path
|
||||||
|
d="M19.5009 35.9989L5.5009 21.9989L0.834229 26.6655L19.5009 45.3322L59.5009 5.33219L54.8342 0.665527L19.5009 35.9989Z">
|
||||||
|
</path>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 370 B |
BIN
public/emoji/input_numbers.webp
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
public/emoji/money.png
Normal file
|
After Width: | Height: | Size: 4.8 KiB |
BIN
public/emoji/rised_hand.webp
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
public/emoji/smiling-face-with-hearts.webp
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
public/emoji/star_struck.webp
Normal file
|
After Width: | Height: | Size: 4.0 KiB |
BIN
public/emoji/sunset.webp
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
public/paywall__astrologers-image.png
Normal file
|
After Width: | Height: | Size: 9.9 KiB |
BIN
public/paywall__spiritist-spiritualist.png
Normal file
|
After Width: | Height: | Size: 38 KiB |
@ -0,0 +1,36 @@
|
|||||||
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
|
import { MultiPageNavigationProvider } from "@/components/domains/additional-purchases";
|
||||||
|
import { loadFunnelPaymentById } from "@/entities/session/funnel/loaders";
|
||||||
|
import { ROUTES } from "@/shared/constants/client-routes";
|
||||||
|
import { ELocalesPlacement } from "@/types";
|
||||||
|
|
||||||
|
interface LayoutProps {
|
||||||
|
children: React.ReactNode;
|
||||||
|
params: Promise<{ pageType: string }>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
funnel: ELocalesPlacement.CompatibilityV2,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async function MultiPageLayout({
|
||||||
|
children,
|
||||||
|
params,
|
||||||
|
}: LayoutProps) {
|
||||||
|
const { pageType } = await params;
|
||||||
|
const pages = await loadFunnelPaymentById(payload, "additionalProducts");
|
||||||
|
|
||||||
|
const allProducts = Array.isArray(pages) ? pages : pages ? [pages] : [];
|
||||||
|
const currentProduct = allProducts.find(page => page.type === pageType);
|
||||||
|
|
||||||
|
if (!currentProduct) {
|
||||||
|
return redirect(ROUTES.home());
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MultiPageNavigationProvider data={allProducts} currentType={pageType}>
|
||||||
|
{children}
|
||||||
|
</MultiPageNavigationProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
|
import {
|
||||||
|
AddConsultantPage,
|
||||||
|
AddGuidesPage,
|
||||||
|
} from "@/components/domains/additional-purchases";
|
||||||
|
import { ROUTES } from "@/shared/constants/client-routes";
|
||||||
|
|
||||||
|
interface AdditionalProductPageProps {
|
||||||
|
params: Promise<{ pageType: string }>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function AdditionalProductPage({
|
||||||
|
params,
|
||||||
|
}: AdditionalProductPageProps) {
|
||||||
|
const { pageType } = await params;
|
||||||
|
|
||||||
|
switch (pageType) {
|
||||||
|
case "add_consultant":
|
||||||
|
return <AddConsultantPage />;
|
||||||
|
case "add_guides":
|
||||||
|
return <AddGuidesPage />;
|
||||||
|
default:
|
||||||
|
return redirect(ROUTES.home());
|
||||||
|
}
|
||||||
|
}
|
||||||
19
src/app/[locale]/(additional-purchases)/ap/page.tsx
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
|
import { loadFunnelPaymentById } from "@/entities/session/funnel/loaders";
|
||||||
|
import { ROUTES } from "@/shared/constants/client-routes";
|
||||||
|
import { ELocalesPlacement } from "@/types";
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
funnel: ELocalesPlacement.CompatibilityV2,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async function AdditionalPurchasesPage() {
|
||||||
|
const pages = await loadFunnelPaymentById(payload, "additionalProducts");
|
||||||
|
|
||||||
|
if (!pages || !Array.isArray(pages) || pages.length === 0) {
|
||||||
|
return redirect(ROUTES.home());
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect(ROUTES.additionalPurchases(pages[0].type));
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
.layout {
|
||||||
|
position: relative;
|
||||||
|
padding: 24px;
|
||||||
|
padding-bottom: 120px;
|
||||||
|
min-height: 100dvh;
|
||||||
|
height: fit-content;
|
||||||
|
}
|
||||||
9
src/app/[locale]/(additional-purchases)/layout.tsx
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import styles from "./layout.module.scss";
|
||||||
|
|
||||||
|
export default function AdditionalPurchasesLayout({
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
return <section className={styles.layout}>{children}</section>;
|
||||||
|
}
|
||||||
@ -1,5 +1,4 @@
|
|||||||
import { DrawerProvider, Header } from "@/components/layout";
|
import { DrawerProvider, Header, NavigationBar } from "@/components/layout";
|
||||||
import NavigationBar from "@/components/layout/NavigationBar/NavigationBar";
|
|
||||||
|
|
||||||
import styles from "./layout.module.scss";
|
import styles from "./layout.module.scss";
|
||||||
|
|
||||||
|
|||||||
11
src/app/[locale]/(payment)/layout.module.scss
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
.main {
|
||||||
|
padding: 16px;
|
||||||
|
padding-bottom: 120px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navBar {
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
z-index: 7777;
|
||||||
|
background: var(--background);
|
||||||
|
}
|
||||||
16
src/app/[locale]/(payment)/layout.tsx
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { DrawerProvider, Header } from "@/components/layout";
|
||||||
|
|
||||||
|
import styles from "./layout.module.scss";
|
||||||
|
|
||||||
|
export default function CoreLayout({
|
||||||
|
children,
|
||||||
|
}: Readonly<{
|
||||||
|
children: React.ReactNode;
|
||||||
|
}>) {
|
||||||
|
return (
|
||||||
|
<DrawerProvider>
|
||||||
|
<Header className={styles.navBar} />
|
||||||
|
<main className={styles.main}>{children}</main>
|
||||||
|
</DrawerProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -24,8 +24,8 @@ export default function Metrics({
|
|||||||
|
|
||||||
const [isButtonVisible, setIsButtonVisible] = useState(false);
|
const [isButtonVisible, setIsButtonVisible] = useState(false);
|
||||||
|
|
||||||
const navigateToHome = () => {
|
const handleNext = () => {
|
||||||
window.location.href = ROUTES.home();
|
window.location.href = ROUTES.additionalPurchases();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Yandex Metrica
|
// Yandex Metrica
|
||||||
@ -186,7 +186,7 @@ fbq('track', 'Purchase', { value: ${productPrice}, currency: "${currency}" });`}
|
|||||||
))}
|
))}
|
||||||
|
|
||||||
{isButtonVisible && (
|
{isButtonVisible && (
|
||||||
<Button onClick={navigateToHome} className={styles.button}>
|
<Button onClick={handleNext} className={styles.button}>
|
||||||
<Typography color="white">{t("button")}</Typography>
|
<Typography color="white">{t("button")}</Typography>
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
.container.container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
-webkit-box-align: center;
|
||||||
|
align-items: center;
|
||||||
|
width: 100%;
|
||||||
|
height: fit-content;
|
||||||
|
max-width: 560px;
|
||||||
|
position: fixed;
|
||||||
|
bottom: 0dvh;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
margin-top: 0px;
|
||||||
|
padding-bottom: 20px;
|
||||||
|
padding-inline: 15px;
|
||||||
|
z-index: 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button.button {
|
||||||
|
padding-block: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skipButton.skipButton {
|
||||||
|
background-color: transparent;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
@ -0,0 +1,81 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useTranslations } from "next-intl";
|
||||||
|
|
||||||
|
import { Button, Spinner, Typography } from "@/components/ui";
|
||||||
|
import { BlurComponent } from "@/components/widgets";
|
||||||
|
import { useSingleCheckout } from "@/hooks/payment/useSingleCheckout";
|
||||||
|
import { useToast } from "@/providers/toast-provider";
|
||||||
|
|
||||||
|
import styles from "./AddConsultantButton.module.scss";
|
||||||
|
|
||||||
|
import { useMultiPageNavigationContext } from "..";
|
||||||
|
|
||||||
|
export default function AddConsultantButton() {
|
||||||
|
const t = useTranslations("AdditionalPurchases.add-consultant");
|
||||||
|
const { addToast } = useToast();
|
||||||
|
const { navigation } = useMultiPageNavigationContext();
|
||||||
|
const data = navigation.currentItem;
|
||||||
|
|
||||||
|
const product = data?.variants?.[0];
|
||||||
|
|
||||||
|
const { handleSingleCheckout, isLoading } = useSingleCheckout({
|
||||||
|
onSuccess: () => {
|
||||||
|
navigation.goToNext();
|
||||||
|
},
|
||||||
|
onError: _error => {
|
||||||
|
addToast({
|
||||||
|
variant: "error",
|
||||||
|
message: t("payment_error"),
|
||||||
|
duration: 5000,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleGetConsultation = () => {
|
||||||
|
if (!product) {
|
||||||
|
addToast({
|
||||||
|
variant: "error",
|
||||||
|
message: t("payment_error"),
|
||||||
|
duration: 5000,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSingleCheckout({
|
||||||
|
productId: product.id,
|
||||||
|
key: product.key,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSkipOffer = () => {
|
||||||
|
navigation.goToNext();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BlurComponent isActiveBlur={true} className={styles.container}>
|
||||||
|
<Button
|
||||||
|
className={styles.button}
|
||||||
|
onClick={handleGetConsultation}
|
||||||
|
disabled={isLoading || !product}
|
||||||
|
>
|
||||||
|
{isLoading ? (
|
||||||
|
<Spinner />
|
||||||
|
) : (
|
||||||
|
<Typography weight="semiBold" color="white">
|
||||||
|
{t("get_my_consultation")}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
className={styles.skipButton}
|
||||||
|
onClick={handleSkipOffer}
|
||||||
|
disabled={isLoading}
|
||||||
|
>
|
||||||
|
<Typography size="sm" color="black">
|
||||||
|
{t("skip_this_offer")}
|
||||||
|
</Typography>
|
||||||
|
</Button>
|
||||||
|
</BlurComponent>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
.title.title {
|
||||||
|
color: #086de5;
|
||||||
|
margin-top: 24px;
|
||||||
|
margin-bottom: 6px;
|
||||||
|
line-height: 150%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.exclusiveOffer.exclusiveOffer {
|
||||||
|
width: 100%;
|
||||||
|
background-color: #e7f5fd;
|
||||||
|
padding: 8px 16px;
|
||||||
|
border-radius: 8px;
|
||||||
|
line-height: 125%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.consultationTable.consultationTable {
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
import { useTranslations } from "next-intl";
|
||||||
|
|
||||||
|
import {
|
||||||
|
AddConsultantButton,
|
||||||
|
Caution,
|
||||||
|
ConsultationTable,
|
||||||
|
} from "@/components/domains/additional-purchases";
|
||||||
|
import { Card, Typography } from "@/components/ui";
|
||||||
|
|
||||||
|
import styles from "./AddConsultantPage.module.scss";
|
||||||
|
|
||||||
|
export default function AddConsultantPage() {
|
||||||
|
const t = useTranslations("AdditionalPurchases.add-consultant");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Caution />
|
||||||
|
<Typography as="h2" size="xl" weight="semiBold" className={styles.title}>
|
||||||
|
{t("title")}
|
||||||
|
</Typography>
|
||||||
|
<Typography
|
||||||
|
as="p"
|
||||||
|
size="sm"
|
||||||
|
color="black"
|
||||||
|
className={styles.exclusiveOffer}
|
||||||
|
>
|
||||||
|
{t("exclusive_offer")}
|
||||||
|
</Typography>
|
||||||
|
<Card className={styles.consultationTable}>
|
||||||
|
<ConsultationTable />
|
||||||
|
</Card>
|
||||||
|
<AddConsultantButton />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
.container {
|
||||||
|
position: fixed;
|
||||||
|
bottom: calc(0dvh + 16px);
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
width: 100%;
|
||||||
|
padding-inline: 24px;
|
||||||
|
max-width: 560px;
|
||||||
|
height: fit-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
padding-block: 16px;
|
||||||
|
}
|
||||||
@ -0,0 +1,74 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useTranslations } from "next-intl";
|
||||||
|
|
||||||
|
import { Button, Spinner, Typography } from "@/components/ui";
|
||||||
|
import { BlurComponent } from "@/components/widgets";
|
||||||
|
import { useSingleCheckout } from "@/hooks/payment/useSingleCheckout";
|
||||||
|
import { useToast } from "@/providers/toast-provider";
|
||||||
|
|
||||||
|
import { useProductSelection } from "../ProductSelectionProvider";
|
||||||
|
|
||||||
|
import styles from "./AddGuidesButton.module.scss";
|
||||||
|
|
||||||
|
import { useMultiPageNavigationContext } from "..";
|
||||||
|
|
||||||
|
export default function AddGuidesButton() {
|
||||||
|
const t = useTranslations("AdditionalPurchases.add-guides");
|
||||||
|
const { addToast } = useToast();
|
||||||
|
const { selectedProduct } = useProductSelection();
|
||||||
|
const { navigation } = useMultiPageNavigationContext();
|
||||||
|
|
||||||
|
const { handleSingleCheckout, isLoading } = useSingleCheckout({
|
||||||
|
onSuccess: () => {
|
||||||
|
navigation.goToNext();
|
||||||
|
},
|
||||||
|
onError: _error => {
|
||||||
|
addToast({
|
||||||
|
variant: "error",
|
||||||
|
message: t("payment_error"),
|
||||||
|
duration: 5000,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handlePurchase = () => {
|
||||||
|
if (!selectedProduct) {
|
||||||
|
addToast({
|
||||||
|
variant: "error",
|
||||||
|
message: t("select_product_error"),
|
||||||
|
duration: 5000,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSingleCheckout({
|
||||||
|
productId: selectedProduct.id,
|
||||||
|
key: selectedProduct.key,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSkipOffer = () => {
|
||||||
|
navigation.goToNext();
|
||||||
|
};
|
||||||
|
|
||||||
|
const isSkipOffer = selectedProduct?.id === "main_skip_offer";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BlurComponent isActiveBlur={true} className={styles.container}>
|
||||||
|
<Button
|
||||||
|
className={styles.button}
|
||||||
|
onClick={isSkipOffer ? handleSkipOffer : handlePurchase}
|
||||||
|
disabled={isLoading}
|
||||||
|
>
|
||||||
|
{isLoading ? (
|
||||||
|
<Spinner />
|
||||||
|
) : (
|
||||||
|
<Typography weight="semiBold" color="white">
|
||||||
|
{isSkipOffer ? t("skip_offer") : t("button")}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</BlurComponent>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
.title {
|
||||||
|
font-size: 18px;
|
||||||
|
line-height: 135%;
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.subtitle {
|
||||||
|
color: #066fdf;
|
||||||
|
margin-block: 8px;
|
||||||
|
line-height: 135%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.description {
|
||||||
|
display: block;
|
||||||
|
margin: 20px auto;
|
||||||
|
font-size: 10px;
|
||||||
|
line-height: 125%;
|
||||||
|
}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
import { Suspense } from "react";
|
||||||
|
import { useTranslations } from "next-intl";
|
||||||
|
|
||||||
|
import {
|
||||||
|
AddGuidesButton,
|
||||||
|
Caution,
|
||||||
|
Offers,
|
||||||
|
OffersSkeleton,
|
||||||
|
ProductSelectionProvider,
|
||||||
|
} from "@/components/domains/additional-purchases";
|
||||||
|
import { Typography } from "@/components/ui";
|
||||||
|
|
||||||
|
import styles from "./AddGuidesPage.module.scss";
|
||||||
|
|
||||||
|
export default function AddGuidesPage() {
|
||||||
|
const t = useTranslations("AdditionalPurchases.add-guides");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ProductSelectionProvider>
|
||||||
|
<Caution />
|
||||||
|
<Typography as="h2" size="xl" weight="semiBold" className={styles.title}>
|
||||||
|
{t("title")}
|
||||||
|
</Typography>
|
||||||
|
<Typography as="h3" size="sm" className={styles.subtitle}>
|
||||||
|
{t("subtitle")}
|
||||||
|
</Typography>
|
||||||
|
<Suspense fallback={<OffersSkeleton />}>
|
||||||
|
<Offers />
|
||||||
|
</Suspense>
|
||||||
|
<Typography align="left" color="secondary" className={styles.description}>
|
||||||
|
{t("description")}
|
||||||
|
</Typography>
|
||||||
|
<AddGuidesButton />
|
||||||
|
</ProductSelectionProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
.container.container {
|
||||||
|
width: 100%;
|
||||||
|
padding: 20px;
|
||||||
|
background-color: #aaddff;
|
||||||
|
border-radius: 8px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
gap: 15px;
|
||||||
|
height: min-content;
|
||||||
|
margin-top: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title.title {
|
||||||
|
line-height: 135%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text.text {
|
||||||
|
line-height: 125%;
|
||||||
|
}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
import Image from "next/image";
|
||||||
|
import { useTranslations } from "next-intl";
|
||||||
|
|
||||||
|
import { Typography } from "@/components/ui";
|
||||||
|
|
||||||
|
import styles from "./Caution.module.scss";
|
||||||
|
|
||||||
|
function Caution() {
|
||||||
|
const t = useTranslations("AdditionalPurchases.caution");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.container}>
|
||||||
|
<Image
|
||||||
|
src="/emoji/smiling-face-with-hearts.webp"
|
||||||
|
alt="Love"
|
||||||
|
width={34}
|
||||||
|
height={34}
|
||||||
|
/>
|
||||||
|
<div className={styles["text-container"]}>
|
||||||
|
<Typography
|
||||||
|
as="h4"
|
||||||
|
size="sm"
|
||||||
|
weight="bold"
|
||||||
|
align="left"
|
||||||
|
className={styles.title}
|
||||||
|
>
|
||||||
|
{t("title")}
|
||||||
|
</Typography>
|
||||||
|
<Typography as="p" size="xs" align="left" className={styles.text}>
|
||||||
|
{t("description")}
|
||||||
|
</Typography>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Caution;
|
||||||
@ -0,0 +1,82 @@
|
|||||||
|
.container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
-webkit-box-align: center;
|
||||||
|
align-items: center;
|
||||||
|
position: relative;
|
||||||
|
border-radius: 16px;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
& > .title {
|
||||||
|
font-size: 18px;
|
||||||
|
line-height: 135%;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.header {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
|
||||||
|
& > .textContainer {
|
||||||
|
& > .title {
|
||||||
|
color: #1b6acb;
|
||||||
|
line-height: 125%;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
& > .text {
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 125%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
& > img {
|
||||||
|
height: 100px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.line {
|
||||||
|
width: 100%;
|
||||||
|
height: 1px;
|
||||||
|
background: rgb(203, 203, 203);
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer {
|
||||||
|
margin-top: 16px;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
& > .oneTimePrice {
|
||||||
|
line-height: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
& > .oldPrice {
|
||||||
|
line-height: 24px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
|
||||||
|
& > .save {
|
||||||
|
color: #1b6acb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.chooseContainer {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
margin-top: 16px;
|
||||||
|
|
||||||
|
& > .chooseText {
|
||||||
|
color: #066fdf;
|
||||||
|
line-height: 125%;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,106 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import Image from "next/image";
|
||||||
|
import { useTranslations } from "next-intl";
|
||||||
|
|
||||||
|
import { Typography } from "@/components/ui";
|
||||||
|
import { getFormattedPrice } from "@/shared/utils/price";
|
||||||
|
import { Currency } from "@/types";
|
||||||
|
|
||||||
|
import styles from "./ConsultationTable.module.scss";
|
||||||
|
|
||||||
|
import { useMultiPageNavigationContext } from "..";
|
||||||
|
|
||||||
|
export default function ConsultationTable() {
|
||||||
|
const t = useTranslations("AdditionalPurchases.add-consultant");
|
||||||
|
const { navigation } = useMultiPageNavigationContext();
|
||||||
|
const data = navigation.currentItem;
|
||||||
|
|
||||||
|
const currency = Currency.USD;
|
||||||
|
|
||||||
|
const product = data?.variants?.[0];
|
||||||
|
const discount =
|
||||||
|
data?.properties?.find(p => p.key === "discount")?.value ?? 0;
|
||||||
|
|
||||||
|
const price = getFormattedPrice(product?.price ?? 0, currency);
|
||||||
|
const oldPrice = getFormattedPrice(
|
||||||
|
(Number(product?.price) / (Number(discount) || 100)) * 100,
|
||||||
|
currency
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.container}>
|
||||||
|
<Typography as="h2" weight="bold" className={styles.title}>
|
||||||
|
{t("your_unique_consultation")}
|
||||||
|
</Typography>
|
||||||
|
<div className={styles.header}>
|
||||||
|
<div className={styles.textContainer}>
|
||||||
|
<Typography
|
||||||
|
as="h3"
|
||||||
|
align="left"
|
||||||
|
weight="semiBold"
|
||||||
|
className={styles.title}
|
||||||
|
>
|
||||||
|
{t("30-minute")}
|
||||||
|
</Typography>
|
||||||
|
<Typography as="p" align="left" className={styles.text}>
|
||||||
|
{t("unlock_profound")}
|
||||||
|
</Typography>
|
||||||
|
</div>
|
||||||
|
<Image
|
||||||
|
src="/paywall__spiritist-spiritualist.png"
|
||||||
|
alt="spiritualist"
|
||||||
|
width={76.3}
|
||||||
|
height={100}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className={styles.line} />
|
||||||
|
<div className={styles.footer}>
|
||||||
|
<Typography
|
||||||
|
as="p"
|
||||||
|
color="black"
|
||||||
|
weight="bold"
|
||||||
|
align="left"
|
||||||
|
className={styles.oneTimePrice}
|
||||||
|
>
|
||||||
|
{t.rich("one_time_price_offer", {
|
||||||
|
price: () => (
|
||||||
|
<Typography as="span" weight="bold" size="xl" color="black">
|
||||||
|
{price}
|
||||||
|
</Typography>
|
||||||
|
),
|
||||||
|
})}
|
||||||
|
</Typography>
|
||||||
|
<Typography
|
||||||
|
as="p"
|
||||||
|
color="black"
|
||||||
|
size="sm"
|
||||||
|
align="left"
|
||||||
|
className={styles.oldPrice}
|
||||||
|
>
|
||||||
|
{t("original_price", {
|
||||||
|
oldPrice: oldPrice,
|
||||||
|
})}
|
||||||
|
<Typography weight="bold" className={styles.save}>
|
||||||
|
{t("save", {
|
||||||
|
discount: discount,
|
||||||
|
})}
|
||||||
|
</Typography>
|
||||||
|
</Typography>
|
||||||
|
<div className={styles.line} />
|
||||||
|
<div className={styles.chooseContainer}>
|
||||||
|
<Typography as="p" align="left" className={styles.chooseText}>
|
||||||
|
{t("choose_from")}
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Image
|
||||||
|
src="/paywall__astrologers-image.png"
|
||||||
|
alt="astrologers"
|
||||||
|
width={106}
|
||||||
|
height={40}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { createContext, ReactNode, useContext } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
|
import { IFunnelPaymentPlacement } from "@/entities/session/funnel/types";
|
||||||
|
import { useMultiPageNavigation } from "@/hooks/multiPages/useMultiPageNavigation";
|
||||||
|
import { ROUTES } from "@/shared/constants/client-routes";
|
||||||
|
|
||||||
|
interface MultiPageNavigationContextType {
|
||||||
|
navigation: ReturnType<
|
||||||
|
typeof useMultiPageNavigation<IFunnelPaymentPlacement>
|
||||||
|
>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const MultiPageNavigationContext = createContext<
|
||||||
|
MultiPageNavigationContextType | undefined
|
||||||
|
>(undefined);
|
||||||
|
|
||||||
|
interface MultiPageNavigationProviderProps {
|
||||||
|
children: ReactNode;
|
||||||
|
data: IFunnelPaymentPlacement[];
|
||||||
|
currentType: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function MultiPageNavigationProvider({
|
||||||
|
children,
|
||||||
|
data,
|
||||||
|
currentType,
|
||||||
|
}: MultiPageNavigationProviderProps) {
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const navigation = useMultiPageNavigation<IFunnelPaymentPlacement>({
|
||||||
|
data,
|
||||||
|
currentType,
|
||||||
|
getTypeFromItem: item => item.type ?? "",
|
||||||
|
navigateToItemByType: type => {
|
||||||
|
router.push(ROUTES.additionalPurchases(type));
|
||||||
|
},
|
||||||
|
onComplete: () => {
|
||||||
|
router.push(ROUTES.home());
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MultiPageNavigationContext.Provider value={{ navigation }}>
|
||||||
|
{children}
|
||||||
|
</MultiPageNavigationContext.Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useMultiPageNavigationContext() {
|
||||||
|
const context = useContext(MultiPageNavigationContext);
|
||||||
|
if (!context) {
|
||||||
|
throw new Error(
|
||||||
|
"useMultiPageNavigationContext must be used within MultiPageNavigationProvider"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
}
|
||||||
@ -0,0 +1,92 @@
|
|||||||
|
.container.container {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 24px 1fr auto;
|
||||||
|
-webkit-box-align: center;
|
||||||
|
align-items: center;
|
||||||
|
-webkit-box-pack: justify;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 12px 16px;
|
||||||
|
margin-inline: auto;
|
||||||
|
max-width: 450px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container.active {
|
||||||
|
background: #066fdf;
|
||||||
|
border: 2px solid #066fdf;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mark {
|
||||||
|
border-radius: 50%;
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
display: flex;
|
||||||
|
-webkit-box-align: center;
|
||||||
|
align-items: center;
|
||||||
|
-webkit-box-pack: center;
|
||||||
|
justify-content: center;
|
||||||
|
border: 1px solid #aaddff;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.textContainer {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
-webkit-box-flex: 1;
|
||||||
|
flex-grow: 1;
|
||||||
|
margin-left: 16px;
|
||||||
|
|
||||||
|
& > * {
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
& > .title {
|
||||||
|
text-transform: uppercase;
|
||||||
|
line-height: 135%;
|
||||||
|
}
|
||||||
|
|
||||||
|
& > .subtitle {
|
||||||
|
line-height: 135%;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.priceContainer {
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: rgb(79, 79, 79);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.description {
|
||||||
|
max-width: 140px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.oldPrice {
|
||||||
|
text-decoration: line-through;
|
||||||
|
}
|
||||||
|
|
||||||
|
.discountContainer {
|
||||||
|
background: #a7ddff;
|
||||||
|
border-radius: 4px;
|
||||||
|
display: inline-block;
|
||||||
|
margin-left: 4px;
|
||||||
|
padding-inline: 4px;
|
||||||
|
|
||||||
|
& > .discount {
|
||||||
|
color: #066fdf;
|
||||||
|
line-height: 170%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.emoji {
|
||||||
|
display: inline-block;
|
||||||
|
background-size: contain;
|
||||||
|
background-position: center center;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
margin-left: 3px;
|
||||||
|
}
|
||||||
143
src/components/domains/additional-purchases/Offer/Offer.tsx
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
import Image from "next/image";
|
||||||
|
import { useTranslations } from "next-intl";
|
||||||
|
|
||||||
|
import { Card, Typography } from "@/components/ui";
|
||||||
|
import { IFunnelPaymentVariant } from "@/entities/session/funnel/types";
|
||||||
|
import { getFormattedPrice } from "@/shared/utils/price";
|
||||||
|
import { Currency } from "@/types";
|
||||||
|
|
||||||
|
import styles from "./Offer.module.scss";
|
||||||
|
|
||||||
|
interface OfferProps {
|
||||||
|
offer: IFunnelPaymentVariant;
|
||||||
|
isActive: boolean;
|
||||||
|
className?: string;
|
||||||
|
onClick: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Offer(props: OfferProps) {
|
||||||
|
const { offer, isActive, className, onClick } = props;
|
||||||
|
|
||||||
|
const { key, price, oldPrice } = offer;
|
||||||
|
|
||||||
|
const productKey = key.replaceAll(".", "_");
|
||||||
|
|
||||||
|
const t = useTranslations(
|
||||||
|
`AdditionalPurchases.add-guides.products.${productKey}`
|
||||||
|
);
|
||||||
|
|
||||||
|
const currency = Currency.USD;
|
||||||
|
|
||||||
|
const subtitle = t.has("subtitle") ? t("subtitle") : undefined;
|
||||||
|
|
||||||
|
const discount = (((oldPrice || 0) - price) / (oldPrice || 0)) * 100;
|
||||||
|
|
||||||
|
const emoji = t.has("emoji") ? t("emoji") : undefined;
|
||||||
|
|
||||||
|
const typographyColor = isActive ? "white" : "default";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card
|
||||||
|
className={`${styles.container} ${
|
||||||
|
isActive && styles.active
|
||||||
|
} ${className}`}
|
||||||
|
onClick={onClick}
|
||||||
|
>
|
||||||
|
<div className={styles.mark}>
|
||||||
|
{/* TODO: add icon after merge with chat */}
|
||||||
|
{isActive && (
|
||||||
|
<Image
|
||||||
|
src="/check-mark-1.svg"
|
||||||
|
alt="Checkmark"
|
||||||
|
width={14}
|
||||||
|
height={12}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className={styles.textContainer}>
|
||||||
|
<Typography
|
||||||
|
as="p"
|
||||||
|
align="left"
|
||||||
|
weight="semiBold"
|
||||||
|
className={styles.title}
|
||||||
|
color={typographyColor}
|
||||||
|
>
|
||||||
|
{t("title")}
|
||||||
|
</Typography>
|
||||||
|
{!!subtitle?.length && productKey !== "main_skip_offer" && (
|
||||||
|
<Typography
|
||||||
|
align="left"
|
||||||
|
size="sm"
|
||||||
|
color={typographyColor}
|
||||||
|
className={styles.subtitle}
|
||||||
|
>
|
||||||
|
{subtitle}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
<div className={styles.priceContainer}>
|
||||||
|
{productKey !== "main_skip_offer" && (
|
||||||
|
<Typography
|
||||||
|
align="left"
|
||||||
|
color={typographyColor}
|
||||||
|
size="xs"
|
||||||
|
weight="semiBold"
|
||||||
|
className={styles.price}
|
||||||
|
>
|
||||||
|
{t.rich("price", {
|
||||||
|
price: () => (
|
||||||
|
<Typography
|
||||||
|
size="sm"
|
||||||
|
color={typographyColor}
|
||||||
|
weight="semiBold"
|
||||||
|
className={styles.currentPrice}
|
||||||
|
>
|
||||||
|
{getFormattedPrice(price, currency)}
|
||||||
|
</Typography>
|
||||||
|
),
|
||||||
|
oldPrice: () => (
|
||||||
|
<Typography
|
||||||
|
size="xs"
|
||||||
|
color={typographyColor}
|
||||||
|
weight="semiBold"
|
||||||
|
className={styles.oldPrice}
|
||||||
|
>
|
||||||
|
{getFormattedPrice(oldPrice || 0, currency)}
|
||||||
|
</Typography>
|
||||||
|
),
|
||||||
|
})}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{productKey === "main_skip_offer" && (
|
||||||
|
<Typography
|
||||||
|
align="left"
|
||||||
|
size="xs"
|
||||||
|
color={typographyColor}
|
||||||
|
className={styles.description}
|
||||||
|
>
|
||||||
|
{subtitle}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{productKey !== "ultra_pack" && (
|
||||||
|
<div className={styles.discountContainer}>
|
||||||
|
<Typography
|
||||||
|
size="xs"
|
||||||
|
weight="semiBold"
|
||||||
|
className={styles.discount}
|
||||||
|
>
|
||||||
|
{t("discount", {
|
||||||
|
discount: discount || 0,
|
||||||
|
})}
|
||||||
|
</Typography>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span
|
||||||
|
className={styles.emoji}
|
||||||
|
style={{ backgroundImage: `url(/emoji/${emoji})` }}
|
||||||
|
/>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
.container {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useMemo, useState } from "react";
|
||||||
|
|
||||||
|
import { Skeleton } from "@/components/ui";
|
||||||
|
import { IFunnelPaymentVariant } from "@/entities/session/funnel/types";
|
||||||
|
|
||||||
|
import { useProductSelection } from "../ProductSelectionProvider";
|
||||||
|
|
||||||
|
import styles from "./Offers.module.scss";
|
||||||
|
|
||||||
|
import { Offer, useMultiPageNavigationContext } from "..";
|
||||||
|
|
||||||
|
export default function Offers() {
|
||||||
|
const { navigation } = useMultiPageNavigationContext();
|
||||||
|
const data = navigation.currentItem;
|
||||||
|
|
||||||
|
const offers = useMemo(() => data?.variants ?? [], [data]);
|
||||||
|
const [allOffers, setAllOffers] = useState<IFunnelPaymentVariant[]>([]);
|
||||||
|
const [activeOffer, setActiveOffer] = useState<string>("");
|
||||||
|
const { setSelectedProduct } = useProductSelection();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const skipOffer: IFunnelPaymentVariant = {
|
||||||
|
id: "main_skip_offer",
|
||||||
|
key: "main.skip.offer",
|
||||||
|
type: "one_time",
|
||||||
|
price: 0,
|
||||||
|
oldPrice: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
const offersWithSkip = [...offers, skipOffer];
|
||||||
|
setAllOffers(offersWithSkip);
|
||||||
|
setActiveOffer(offers[0]?.id || skipOffer.id);
|
||||||
|
|
||||||
|
// Устанавливаем первый продукт как выбранный по умолчанию
|
||||||
|
if (offers[0]) {
|
||||||
|
setSelectedProduct(offers[0]);
|
||||||
|
}
|
||||||
|
}, [offers, setSelectedProduct]);
|
||||||
|
|
||||||
|
const handleOfferClick = (offer: IFunnelPaymentVariant) => {
|
||||||
|
setActiveOffer(offer.id);
|
||||||
|
setSelectedProduct(offer);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.container}>
|
||||||
|
{allOffers.map(offer => (
|
||||||
|
<Offer
|
||||||
|
offer={offer}
|
||||||
|
key={offer.id}
|
||||||
|
isActive={activeOffer === offer.id}
|
||||||
|
onClick={() => handleOfferClick(offer)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function OffersSkeleton() {
|
||||||
|
return <Skeleton style={{ height: "400px" }} />;
|
||||||
|
}
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { createContext, ReactNode, useContext, useState } from "react";
|
||||||
|
|
||||||
|
import { IFunnelPaymentVariant } from "@/entities/session/funnel/types";
|
||||||
|
|
||||||
|
interface ProductSelectionContextType {
|
||||||
|
selectedProduct: IFunnelPaymentVariant | null;
|
||||||
|
setSelectedProduct: (product: IFunnelPaymentVariant | null) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ProductSelectionContext = createContext<
|
||||||
|
ProductSelectionContextType | undefined
|
||||||
|
>(undefined);
|
||||||
|
|
||||||
|
interface ProductSelectionProviderProps {
|
||||||
|
children: ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ProductSelectionProvider({
|
||||||
|
children,
|
||||||
|
}: ProductSelectionProviderProps) {
|
||||||
|
const [selectedProduct, setSelectedProduct] =
|
||||||
|
useState<IFunnelPaymentVariant | null>(null);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ProductSelectionContext.Provider
|
||||||
|
value={{ selectedProduct, setSelectedProduct }}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</ProductSelectionContext.Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useProductSelection() {
|
||||||
|
const context = useContext(ProductSelectionContext);
|
||||||
|
if (!context) {
|
||||||
|
throw new Error(
|
||||||
|
"useProductSelection must be used within ProductSelectionProvider"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
}
|
||||||
16
src/components/domains/additional-purchases/index.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
export { default as AddConsultantButton } from "./AddConsultantButton/AddConsultantButton";
|
||||||
|
export { default as AddConsultantPage } from "./AddConsultantPage/AddConsultantPage";
|
||||||
|
export { default as AddGuidesButton } from "./AddGuidesButton/AddGuidesButton";
|
||||||
|
export { default as AddGuidesPage } from "./AddGuidesPage/AddGuidesPage";
|
||||||
|
export { default as Caution } from "./Caution/Caution";
|
||||||
|
export { default as ConsultationTable } from "./ConsultationTable/ConsultationTable";
|
||||||
|
export {
|
||||||
|
MultiPageNavigationProvider,
|
||||||
|
useMultiPageNavigationContext,
|
||||||
|
} from "./MultiPageNavigationProvider";
|
||||||
|
export { default as Offer } from "./Offer/Offer";
|
||||||
|
export { default as Offers, OffersSkeleton } from "./Offers/Offers";
|
||||||
|
export {
|
||||||
|
ProductSelectionProvider,
|
||||||
|
useProductSelection,
|
||||||
|
} from "./ProductSelectionProvider";
|
||||||
@ -1,4 +1,5 @@
|
|||||||
export { DrawerProvider, useDrawer } from "./Drawer/DrawerContext";
|
export { DrawerProvider, useDrawer } from "./Drawer/DrawerContext";
|
||||||
export { default as Header } from "./Header/Header";
|
export { default as Header } from "./Header/Header";
|
||||||
export { default as Logo } from "./Logo/Logo";
|
export { default as Logo } from "./Logo/Logo";
|
||||||
|
export { default as NavigationBar } from "./NavigationBar/NavigationBar";
|
||||||
export { default as StepperBar } from "./StepperBar/StepperBar";
|
export { default as StepperBar } from "./StepperBar/StepperBar";
|
||||||
|
|||||||
@ -1,17 +1,12 @@
|
|||||||
import { ReactNode } from "react";
|
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
|
|
||||||
import styles from "./Card.module.scss";
|
import styles from "./Card.module.scss";
|
||||||
|
|
||||||
type CardProps = {
|
type CardProps = React.HTMLAttributes<HTMLDivElement>;
|
||||||
children: ReactNode;
|
|
||||||
className?: string;
|
|
||||||
style?: React.CSSProperties;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function Card({ children, className, style }: CardProps) {
|
export default function Card({ children, className, ...props }: CardProps) {
|
||||||
return (
|
return (
|
||||||
<div className={clsx(styles.card, className)} style={style}>
|
<div className={clsx(styles.card, className)} {...props}>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -5,6 +5,11 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
text-align: -webkit-center;
|
text-align: -webkit-center;
|
||||||
|
|
||||||
|
& > * {
|
||||||
|
position: relative;
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
|
||||||
.gradientBlur {
|
.gradientBlur {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 5;
|
z-index: 5;
|
||||||
|
|||||||
34
src/entities/payment/actions.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
"use server";
|
||||||
|
|
||||||
|
import { http } from "@/shared/api/httpClient";
|
||||||
|
import { API_ROUTES } from "@/shared/constants/api-routes";
|
||||||
|
import { ActionResponse } from "@/types";
|
||||||
|
|
||||||
|
import {
|
||||||
|
SingleCheckoutRequest,
|
||||||
|
SingleCheckoutResponse,
|
||||||
|
SingleCheckoutResponseSchema,
|
||||||
|
} from "./types";
|
||||||
|
|
||||||
|
export async function performSingleCheckout(
|
||||||
|
payload: SingleCheckoutRequest
|
||||||
|
): Promise<ActionResponse<SingleCheckoutResponse>> {
|
||||||
|
try {
|
||||||
|
const response = await http.post<SingleCheckoutResponse>(
|
||||||
|
API_ROUTES.paymentSingleCheckout(),
|
||||||
|
payload,
|
||||||
|
{
|
||||||
|
schema: SingleCheckoutResponseSchema,
|
||||||
|
revalidate: 0,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return { data: response, error: null };
|
||||||
|
} catch (error) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error("Failed to perform single checkout:", error);
|
||||||
|
const errorMessage =
|
||||||
|
error instanceof Error ? error.message : "Something went wrong.";
|
||||||
|
return { data: null, error: errorMessage };
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,6 +5,9 @@ import {
|
|||||||
CheckoutRequest,
|
CheckoutRequest,
|
||||||
CheckoutResponse,
|
CheckoutResponse,
|
||||||
CheckoutResponseSchema,
|
CheckoutResponseSchema,
|
||||||
|
SingleCheckoutRequest,
|
||||||
|
SingleCheckoutResponse,
|
||||||
|
SingleCheckoutResponseSchema,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
export async function createPaymentCheckout(payload: CheckoutRequest) {
|
export async function createPaymentCheckout(payload: CheckoutRequest) {
|
||||||
@ -13,3 +16,16 @@ export async function createPaymentCheckout(payload: CheckoutRequest) {
|
|||||||
revalidate: 0,
|
revalidate: 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function createSinglePaymentCheckout(
|
||||||
|
payload: SingleCheckoutRequest
|
||||||
|
) {
|
||||||
|
return http.post<SingleCheckoutResponse>(
|
||||||
|
API_ROUTES.paymentSingleCheckout(),
|
||||||
|
payload,
|
||||||
|
{
|
||||||
|
schema: SingleCheckoutResponseSchema,
|
||||||
|
revalidate: 0,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@ -13,3 +13,37 @@ export const CheckoutResponseSchema = z.object({
|
|||||||
paymentUrl: z.string().url(),
|
paymentUrl: z.string().url(),
|
||||||
});
|
});
|
||||||
export type CheckoutResponse = z.infer<typeof CheckoutResponseSchema>;
|
export type CheckoutResponse = z.infer<typeof CheckoutResponseSchema>;
|
||||||
|
|
||||||
|
export const PaymentInfoSchema = z.object({
|
||||||
|
productId: z.string(),
|
||||||
|
key: z.string(),
|
||||||
|
});
|
||||||
|
export type PaymentInfo = z.infer<typeof PaymentInfoSchema>;
|
||||||
|
|
||||||
|
export const SingleCheckoutRequestSchema = z.object({
|
||||||
|
paymentInfo: PaymentInfoSchema,
|
||||||
|
return_url: z.string().optional(),
|
||||||
|
});
|
||||||
|
export type SingleCheckoutRequest = z.infer<typeof SingleCheckoutRequestSchema>;
|
||||||
|
|
||||||
|
export const SingleCheckoutSuccessSchema = z.object({
|
||||||
|
payment: z.object({
|
||||||
|
status: z.string(),
|
||||||
|
invoiceId: z.string(),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
export type SingleCheckoutSuccess = z.infer<typeof SingleCheckoutSuccessSchema>;
|
||||||
|
|
||||||
|
export const SingleCheckoutErrorSchema = z.object({
|
||||||
|
status: z.string(),
|
||||||
|
message: z.string(),
|
||||||
|
});
|
||||||
|
export type SingleCheckoutError = z.infer<typeof SingleCheckoutErrorSchema>;
|
||||||
|
|
||||||
|
export const SingleCheckoutResponseSchema = z.union([
|
||||||
|
SingleCheckoutSuccessSchema,
|
||||||
|
SingleCheckoutErrorSchema,
|
||||||
|
]);
|
||||||
|
export type SingleCheckoutResponse = z.infer<
|
||||||
|
typeof SingleCheckoutResponseSchema
|
||||||
|
>;
|
||||||
|
|||||||
12
src/entities/session/funnel/api.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { http } from "@/shared/api/httpClient";
|
||||||
|
import { API_ROUTES } from "@/shared/constants/api-routes";
|
||||||
|
|
||||||
|
import { FunnelRequest, FunnelResponse, FunnelResponseSchema } from "./types";
|
||||||
|
|
||||||
|
export const getFunnel = async (payload: FunnelRequest) => {
|
||||||
|
return http.post<FunnelResponse>(API_ROUTES.funnel(), payload, {
|
||||||
|
tags: ["funnel"],
|
||||||
|
schema: FunnelResponseSchema,
|
||||||
|
revalidate: 0,
|
||||||
|
});
|
||||||
|
};
|
||||||
41
src/entities/session/funnel/loaders.ts
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import { cache } from "react";
|
||||||
|
|
||||||
|
import { getFunnel } from "./api";
|
||||||
|
import type { FunnelRequest } from "./types";
|
||||||
|
|
||||||
|
export const loadFunnel = cache((payload: FunnelRequest) => getFunnel(payload));
|
||||||
|
|
||||||
|
export const loadFunnelData = cache((payload: FunnelRequest) =>
|
||||||
|
loadFunnel(payload).then(d => d.data)
|
||||||
|
);
|
||||||
|
|
||||||
|
export const loadFunnelStatus = cache((payload: FunnelRequest) =>
|
||||||
|
loadFunnel(payload).then(d => d.status)
|
||||||
|
);
|
||||||
|
|
||||||
|
export const loadFunnelCurrency = cache((payload: FunnelRequest) =>
|
||||||
|
loadFunnelData(payload).then(d => d.currency)
|
||||||
|
);
|
||||||
|
|
||||||
|
export const loadFunnelLocale = cache((payload: FunnelRequest) =>
|
||||||
|
loadFunnelData(payload).then(d => d.locale)
|
||||||
|
);
|
||||||
|
|
||||||
|
export const loadFunnelPayment = cache((payload: FunnelRequest) =>
|
||||||
|
loadFunnelData(payload).then(d => d.payment)
|
||||||
|
);
|
||||||
|
|
||||||
|
export const loadFunnelPaymentById = cache(
|
||||||
|
(payload: FunnelRequest, paymentId: string) =>
|
||||||
|
loadFunnelData(payload).then(d => d.payment[paymentId])
|
||||||
|
);
|
||||||
|
|
||||||
|
// export const loadFunnelProducts = cache(
|
||||||
|
// (payload: FunnelRequest, paymentId: string) =>
|
||||||
|
// loadFunnelPaymentById(payload, paymentId).then(d => d?.variants ?? [])
|
||||||
|
// );
|
||||||
|
|
||||||
|
// export const loadFunnelProperties = cache(
|
||||||
|
// (payload: FunnelRequest, paymentId: string) =>
|
||||||
|
// loadFunnelPaymentById(payload, paymentId).then(d => d?.properties ?? [])
|
||||||
|
// );
|
||||||
68
src/entities/session/funnel/types.ts
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
import { Currency, ELocalesPlacement } from "../../../types";
|
||||||
|
|
||||||
|
// Request schemas
|
||||||
|
export const FunnelRequestSchema = z.object({
|
||||||
|
funnel: z.nativeEnum(ELocalesPlacement),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Response schemas
|
||||||
|
export const FunnelPaymentPropertySchema = z.object({
|
||||||
|
key: z.string(),
|
||||||
|
value: z.union([z.string(), z.number()]),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const FunnelPaymentVariantSchema = z.object({
|
||||||
|
id: z.string(),
|
||||||
|
key: z.string(),
|
||||||
|
type: z.string(),
|
||||||
|
price: z.number(),
|
||||||
|
oldPrice: z.number().optional(),
|
||||||
|
trialPrice: z.number().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const FunnelPaymentPlacementSchema = z.object({
|
||||||
|
price: z.number().optional(),
|
||||||
|
currency: z.nativeEnum(Currency).optional(),
|
||||||
|
billingPeriod: z.enum(["DAY", "WEEK", "MONTH", "YEAR"]).optional(),
|
||||||
|
billingInterval: z.number().optional(),
|
||||||
|
trialPeriod: z.enum(["DAY", "WEEK", "MONTH", "YEAR"]).optional(),
|
||||||
|
trialInterval: z.number().optional(),
|
||||||
|
placementId: z.string().optional(),
|
||||||
|
paywallId: z.string().optional(),
|
||||||
|
properties: z.array(FunnelPaymentPropertySchema).optional(),
|
||||||
|
variants: z.array(FunnelPaymentVariantSchema).optional(),
|
||||||
|
paymentUrl: z.string().optional(),
|
||||||
|
type: z.string().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const FunnelSchema = z.object({
|
||||||
|
currency: z.nativeEnum(Currency),
|
||||||
|
funnel: z.nativeEnum(ELocalesPlacement),
|
||||||
|
locale: z.string(),
|
||||||
|
payment: z.record(
|
||||||
|
z.string(),
|
||||||
|
z.union([
|
||||||
|
FunnelPaymentPlacementSchema.nullable(),
|
||||||
|
z.array(FunnelPaymentPlacementSchema),
|
||||||
|
])
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const FunnelResponseSchema = z.object({
|
||||||
|
status: z.union([z.literal("success"), z.string()]),
|
||||||
|
data: FunnelSchema,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Type exports
|
||||||
|
export type FunnelRequest = z.infer<typeof FunnelRequestSchema>;
|
||||||
|
export type IFunnelPaymentProperty = z.infer<
|
||||||
|
typeof FunnelPaymentPropertySchema
|
||||||
|
>;
|
||||||
|
export type IFunnelPaymentVariant = z.infer<typeof FunnelPaymentVariantSchema>;
|
||||||
|
export type IFunnelPaymentPlacement = z.infer<
|
||||||
|
typeof FunnelPaymentPlacementSchema
|
||||||
|
>;
|
||||||
|
export type IFunnel = z.infer<typeof FunnelSchema>;
|
||||||
|
export type FunnelResponse = z.infer<typeof FunnelResponseSchema>;
|
||||||
142
src/hooks/multiPages/useMultiPageNavigation.ts
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useCallback, useMemo } from "react";
|
||||||
|
|
||||||
|
interface PageNavigationOptions<T> {
|
||||||
|
data: T[];
|
||||||
|
currentType: string;
|
||||||
|
getTypeFromItem: (item: T) => string;
|
||||||
|
navigateToItemByType: (type: string) => void;
|
||||||
|
onBeforeNext?: (nextItem: T) => boolean | Promise<boolean>;
|
||||||
|
onBeforePrevious?: (prevItem: T) => boolean | Promise<boolean>;
|
||||||
|
onComplete: () => void;
|
||||||
|
onStart?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PageNavigationReturn<T> {
|
||||||
|
currentItem: T | undefined;
|
||||||
|
currentIndex: number;
|
||||||
|
isFirst: boolean;
|
||||||
|
isLast: boolean;
|
||||||
|
hasNext: boolean;
|
||||||
|
hasPrevious: boolean;
|
||||||
|
goToNext: () => Promise<void>;
|
||||||
|
goToPrevious: () => Promise<void>;
|
||||||
|
goToFirst: () => Promise<void>;
|
||||||
|
goToLast: () => Promise<void>;
|
||||||
|
goToIndex: (index: number) => Promise<void>;
|
||||||
|
totalPages: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useMultiPageNavigation<T>({
|
||||||
|
data,
|
||||||
|
currentType,
|
||||||
|
getTypeFromItem,
|
||||||
|
navigateToItemByType,
|
||||||
|
onBeforeNext,
|
||||||
|
onBeforePrevious,
|
||||||
|
onComplete,
|
||||||
|
onStart,
|
||||||
|
}: PageNavigationOptions<T>): PageNavigationReturn<T> {
|
||||||
|
const currentIndex = useMemo(
|
||||||
|
() => data.findIndex(item => getTypeFromItem(item) === currentType),
|
||||||
|
[data, currentType, getTypeFromItem]
|
||||||
|
);
|
||||||
|
|
||||||
|
const currentItem = useMemo(() => data[currentIndex], [data, currentIndex]);
|
||||||
|
|
||||||
|
const isFirst = currentIndex === 0;
|
||||||
|
const isLast = currentIndex === data.length - 1;
|
||||||
|
const hasNext = !isLast;
|
||||||
|
const hasPrevious = !isFirst;
|
||||||
|
const totalPages = data.length;
|
||||||
|
|
||||||
|
const navigateToItem = useCallback(
|
||||||
|
async (item: T) => {
|
||||||
|
const type = getTypeFromItem(item);
|
||||||
|
navigateToItemByType(type);
|
||||||
|
},
|
||||||
|
[navigateToItemByType, getTypeFromItem]
|
||||||
|
);
|
||||||
|
|
||||||
|
const goToNext = useCallback(async () => {
|
||||||
|
if (!hasNext) return onComplete();
|
||||||
|
|
||||||
|
const nextItem = data[currentIndex + 1];
|
||||||
|
|
||||||
|
if (onBeforeNext) {
|
||||||
|
const shouldProceed = await onBeforeNext(nextItem);
|
||||||
|
if (!shouldProceed) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await navigateToItem(nextItem);
|
||||||
|
}, [hasNext, data, currentIndex, onBeforeNext, onComplete, navigateToItem]);
|
||||||
|
|
||||||
|
const goToPrevious = useCallback(async () => {
|
||||||
|
if (!hasPrevious) return;
|
||||||
|
|
||||||
|
const prevItem = data[currentIndex - 1];
|
||||||
|
|
||||||
|
if (onBeforePrevious) {
|
||||||
|
const shouldProceed = await onBeforePrevious(prevItem);
|
||||||
|
if (!shouldProceed) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await navigateToItem(prevItem);
|
||||||
|
}, [hasPrevious, data, currentIndex, onBeforePrevious, navigateToItem]);
|
||||||
|
|
||||||
|
const goToFirst = useCallback(async () => {
|
||||||
|
if (isFirst) return;
|
||||||
|
|
||||||
|
if (onStart) {
|
||||||
|
onStart();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await navigateToItem(data[0]);
|
||||||
|
}, [isFirst, onStart, navigateToItem, data]);
|
||||||
|
|
||||||
|
const goToLast = useCallback(async () => {
|
||||||
|
if (isLast) return;
|
||||||
|
await navigateToItem(data[data.length - 1]);
|
||||||
|
}, [isLast, navigateToItem, data]);
|
||||||
|
|
||||||
|
const goToIndex = useCallback(
|
||||||
|
async (index: number) => {
|
||||||
|
if (index < 0 || index >= data.length || index === currentIndex) return;
|
||||||
|
await navigateToItem(data[index]);
|
||||||
|
},
|
||||||
|
[data, currentIndex, navigateToItem]
|
||||||
|
);
|
||||||
|
|
||||||
|
return useMemo(
|
||||||
|
() => ({
|
||||||
|
currentItem,
|
||||||
|
currentIndex,
|
||||||
|
isFirst,
|
||||||
|
isLast,
|
||||||
|
hasNext,
|
||||||
|
hasPrevious,
|
||||||
|
goToNext,
|
||||||
|
goToPrevious,
|
||||||
|
goToFirst,
|
||||||
|
goToLast,
|
||||||
|
goToIndex,
|
||||||
|
totalPages,
|
||||||
|
}),
|
||||||
|
[
|
||||||
|
currentItem,
|
||||||
|
currentIndex,
|
||||||
|
isFirst,
|
||||||
|
isLast,
|
||||||
|
hasNext,
|
||||||
|
hasPrevious,
|
||||||
|
goToNext,
|
||||||
|
goToPrevious,
|
||||||
|
goToFirst,
|
||||||
|
goToLast,
|
||||||
|
goToIndex,
|
||||||
|
totalPages,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
71
src/hooks/payment/useSingleCheckout.ts
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useCallback, useMemo, useState } from "react";
|
||||||
|
|
||||||
|
import { performSingleCheckout } from "@/entities/payment/actions";
|
||||||
|
import { PaymentInfo, SingleCheckoutRequest } from "@/entities/payment/types";
|
||||||
|
|
||||||
|
interface UseSingleCheckoutOptions {
|
||||||
|
onSuccess?: () => void;
|
||||||
|
onError?: (error: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useSingleCheckout(options: UseSingleCheckoutOptions = {}) {
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
|
const { onSuccess, onError } = options;
|
||||||
|
|
||||||
|
const handleSingleCheckout = useCallback(
|
||||||
|
async (paymentInfo: PaymentInfo) => {
|
||||||
|
if (isLoading) return;
|
||||||
|
|
||||||
|
setIsLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const payload: SingleCheckoutRequest = {
|
||||||
|
paymentInfo,
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await performSingleCheckout(payload);
|
||||||
|
|
||||||
|
if (response.error) {
|
||||||
|
onError?.(response.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!response.data) {
|
||||||
|
onError?.("Payment failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("payment" in response.data) {
|
||||||
|
const { status } = response.data.payment;
|
||||||
|
|
||||||
|
if (status === "paid") {
|
||||||
|
onSuccess?.();
|
||||||
|
} else {
|
||||||
|
onError?.("Payment status is not paid");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const errorMessage = response.data.message || "Payment failed";
|
||||||
|
onError?.(errorMessage);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const errorMessage =
|
||||||
|
error instanceof Error ? error.message : "Payment failed";
|
||||||
|
onError?.(errorMessage);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[onSuccess, onError, isLoading]
|
||||||
|
);
|
||||||
|
|
||||||
|
return useMemo(
|
||||||
|
() => ({
|
||||||
|
handleSingleCheckout,
|
||||||
|
isLoading,
|
||||||
|
}),
|
||||||
|
[handleSingleCheckout, isLoading]
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -15,6 +15,7 @@ export const API_ROUTES = {
|
|||||||
dashboard: () => createRoute(["dashboard"]),
|
dashboard: () => createRoute(["dashboard"]),
|
||||||
subscriptions: () => createRoute(["payment", "subscriptions"], ROOT_ROUTE_V3),
|
subscriptions: () => createRoute(["payment", "subscriptions"], ROOT_ROUTE_V3),
|
||||||
paymentCheckout: () => createRoute(["payment", "checkout"], ROOT_ROUTE_V2),
|
paymentCheckout: () => createRoute(["payment", "checkout"], ROOT_ROUTE_V2),
|
||||||
|
paymentSingleCheckout: () => createRoute(["payment", "checkout"]),
|
||||||
usersMe: () => createRoute(["users", "me"], ROOT_ROUTE),
|
usersMe: () => createRoute(["users", "me"], ROOT_ROUTE),
|
||||||
compatibilityActionFields: (id: string) =>
|
compatibilityActionFields: (id: string) =>
|
||||||
createRoute(["dashboard", "compatibility-actions", id, "fields"]),
|
createRoute(["dashboard", "compatibility-actions", id, "fields"]),
|
||||||
@ -28,4 +29,7 @@ export const API_ROUTES = {
|
|||||||
["payment", "subscriptions", subscriptionId, action],
|
["payment", "subscriptions", subscriptionId, action],
|
||||||
ROOT_ROUTE_V3
|
ROOT_ROUTE_V3
|
||||||
),
|
),
|
||||||
|
|
||||||
|
// session
|
||||||
|
funnel: () => createRoute(["session", "funnel"], ROOT_ROUTE_V2),
|
||||||
};
|
};
|
||||||
|
|||||||
@ -63,6 +63,11 @@ export const ROUTES = {
|
|||||||
// Chat
|
// Chat
|
||||||
chat: () => createRoute(["chat"]),
|
chat: () => createRoute(["chat"]),
|
||||||
|
|
||||||
|
// Additional Purchases
|
||||||
|
addConsultant: () => createRoute(["add-consultant"]),
|
||||||
|
addGuides: () => createRoute(["add-guides"]),
|
||||||
|
additionalPurchases: (type?: string) => createRoute(["ap", type]),
|
||||||
|
|
||||||
// // Compatibility
|
// // Compatibility
|
||||||
// compatibilities: () => createRoute(["compatibilities"]),
|
// compatibilities: () => createRoute(["compatibilities"]),
|
||||||
|
|
||||||
|
|||||||
@ -60,3 +60,26 @@ export type ActionResponse<T> = {
|
|||||||
data: T | null;
|
data: T | null;
|
||||||
error: string | null;
|
error: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export enum ELocalesPlacement {
|
||||||
|
V0 = "v0", // Main site version
|
||||||
|
V1 = "v1",
|
||||||
|
PalmistryV0 = "palmistry-v0",
|
||||||
|
PalmistryV01 = "palmistry-v0_1",
|
||||||
|
PalmistryV1 = "palmistry-v1",
|
||||||
|
PalmistryV11 = "palmistry-v1_1",
|
||||||
|
Chats = "chats",
|
||||||
|
EmailMarketingCompatibilityV1 = "email-marketing-comp-v1",
|
||||||
|
EmailMarketingPalmistryV2 = "email-marketing-palmistry-v2",
|
||||||
|
EmailMarketingCompatibilityV2 = "email-marketing-comp-v2",
|
||||||
|
EmailMarketingCompatibilityV3 = "email-marketing-comp-v3",
|
||||||
|
EmailMarketingCompatibilityV4 = "email-marketing-comp-v4",
|
||||||
|
CompatibilityV2 = "compatibility-v2",
|
||||||
|
CompatibilityV3 = "compatibility-v3",
|
||||||
|
CompatibilityV4 = "compatibility-v4",
|
||||||
|
EmailGenerator = "email-generator",
|
||||||
|
Profile = "profile",
|
||||||
|
RetainingFunnel = "retaining-funnel",
|
||||||
|
}
|
||||||
|
|
||||||
|
export type PeriodType = "DAY" | "WEEK" | "MONTH" | "YEAR";
|
||||||
|
|||||||