Merge pull request #7 from pennyteenycat/AW-493-additional-purchases
Aw 493 additional purchases
@ -215,5 +215,75 @@
|
||||
},
|
||||
"ActionFieldsForm": {
|
||||
"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,6 @@
|
||||
.loading {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100dvh;
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
import { Spinner } from "@/components/ui";
|
||||
|
||||
import styles from "./loading.module.scss";
|
||||
|
||||
export default function AddConsultantLoading() {
|
||||
return (
|
||||
<div className={styles.loading}>
|
||||
<Spinner />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -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,53 @@
|
||||
import { Suspense } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
import {
|
||||
AddConsultantButton,
|
||||
Caution,
|
||||
ConsultationTable,
|
||||
ConsultationTableSkeleton,
|
||||
} from "@/components/domains/additional-purchases";
|
||||
import { Card, Typography } from "@/components/ui";
|
||||
import {
|
||||
loadFunnelProducts,
|
||||
loadFunnelProperties,
|
||||
} from "@/entities/session/funnel/loaders";
|
||||
import { ELocalesPlacement } from "@/types";
|
||||
|
||||
import styles from "./page.module.scss";
|
||||
|
||||
const payload = {
|
||||
funnel: ELocalesPlacement.CompatibilityV2,
|
||||
};
|
||||
|
||||
export default function AddConsultant() {
|
||||
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>
|
||||
<Suspense fallback={<ConsultationTableSkeleton />}>
|
||||
<Card className={styles.consultationTable}>
|
||||
<ConsultationTable
|
||||
products={loadFunnelProducts(payload, "add_consultant")}
|
||||
properties={loadFunnelProperties(payload, "add_consultant")}
|
||||
/>
|
||||
</Card>
|
||||
</Suspense>
|
||||
<AddConsultantButton
|
||||
products={loadFunnelProducts(payload, "add_consultant")}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@ -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%;
|
||||
}
|
||||
42
src/app/[locale]/(additional-purchases)/add-guides/page.tsx
Normal file
@ -0,0 +1,42 @@
|
||||
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 { loadFunnelProducts } from "@/entities/session/funnel/loaders";
|
||||
import { ELocalesPlacement } from "@/types";
|
||||
|
||||
import styles from "./page.module.scss";
|
||||
|
||||
const payload = {
|
||||
funnel: ELocalesPlacement.CompatibilityV2,
|
||||
};
|
||||
|
||||
export default function AddGuides() {
|
||||
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 products={loadFunnelProducts(payload, "add_guides")} />
|
||||
</Suspense>
|
||||
<Typography align="left" color="secondary" className={styles.description}>
|
||||
{t("description")}
|
||||
</Typography>
|
||||
<AddGuidesButton />
|
||||
</ProductSelectionProvider>
|
||||
);
|
||||
}
|
||||
@ -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>;
|
||||
}
|
||||
@ -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,88 @@
|
||||
"use client";
|
||||
|
||||
import { use } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
import { Button, Spinner, Typography } from "@/components/ui";
|
||||
import { BlurComponent } from "@/components/widgets";
|
||||
import { IFunnelPaymentVariant } from "@/entities/session/funnel/types";
|
||||
import { useSingleCheckout } from "@/hooks/payment/useSingleCheckout";
|
||||
import { useToast } from "@/providers/toast-provider";
|
||||
import { ROUTES } from "@/shared/constants/client-routes";
|
||||
|
||||
import styles from "./AddConsultantButton.module.scss";
|
||||
|
||||
interface AddConsultantButtonProps {
|
||||
products: Promise<IFunnelPaymentVariant[]>;
|
||||
}
|
||||
|
||||
export default function AddConsultantButton({
|
||||
products,
|
||||
}: AddConsultantButtonProps) {
|
||||
const router = useRouter();
|
||||
const t = useTranslations("AdditionalPurchases.add-consultant");
|
||||
const { addToast } = useToast();
|
||||
|
||||
const product = use(products)?.[0];
|
||||
|
||||
const { handleSingleCheckout, isLoading } = useSingleCheckout({
|
||||
onSuccess: () => {
|
||||
router.push(ROUTES.addGuides());
|
||||
},
|
||||
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 = () => {
|
||||
router.push(ROUTES.addGuides());
|
||||
};
|
||||
|
||||
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,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 { useRouter } from "next/navigation";
|
||||
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 { ROUTES } from "@/shared/constants/client-routes";
|
||||
|
||||
import { useProductSelection } from "../ProductSelectionContext";
|
||||
|
||||
import styles from "./AddGuidesButton.module.scss";
|
||||
|
||||
export default function AddGuidesButton() {
|
||||
const t = useTranslations("AdditionalPurchases.add-guides");
|
||||
const router = useRouter();
|
||||
const { addToast } = useToast();
|
||||
const { selectedProduct } = useProductSelection();
|
||||
|
||||
const { handleSingleCheckout, isLoading } = useSingleCheckout({
|
||||
onSuccess: () => {
|
||||
router.push(ROUTES.home());
|
||||
},
|
||||
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 = () => {
|
||||
router.push(ROUTES.home());
|
||||
};
|
||||
|
||||
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,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,115 @@
|
||||
import Image from "next/image";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
|
||||
import { Skeleton, Typography } from "@/components/ui";
|
||||
import {
|
||||
IFunnelPaymentProperty,
|
||||
IFunnelPaymentVariant,
|
||||
} from "@/entities/session/funnel/types";
|
||||
import { getFormattedPrice } from "@/shared/utils/price";
|
||||
import { Currency } from "@/types";
|
||||
|
||||
import styles from "./ConsultationTable.module.scss";
|
||||
|
||||
interface ConsultationTableProps {
|
||||
products: Promise<IFunnelPaymentVariant[]>;
|
||||
properties: Promise<IFunnelPaymentProperty[]>;
|
||||
}
|
||||
|
||||
export default async function ConsultationTable({
|
||||
products,
|
||||
properties,
|
||||
}: ConsultationTableProps) {
|
||||
const t = await getTranslations("AdditionalPurchases.add-consultant");
|
||||
const currency = Currency.USD;
|
||||
|
||||
const product = (await products)?.[0];
|
||||
const discount =
|
||||
(await 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>
|
||||
);
|
||||
}
|
||||
|
||||
export function ConsultationTableSkeleton() {
|
||||
return <Skeleton style={{ height: "300px", marginTop: "24px" }} />;
|
||||
}
|
||||
@ -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,64 @@
|
||||
"use client";
|
||||
|
||||
import { use, useEffect, useState } from "react";
|
||||
|
||||
import { Skeleton } from "@/components/ui";
|
||||
import { IFunnelPaymentVariant } from "@/entities/session/funnel/types";
|
||||
|
||||
import { useProductSelection } from "../ProductSelectionContext";
|
||||
|
||||
import styles from "./Offers.module.scss";
|
||||
|
||||
import { Offer } from "..";
|
||||
|
||||
interface OffersProps {
|
||||
products: Promise<IFunnelPaymentVariant[]>;
|
||||
}
|
||||
|
||||
export default function Offers({ products }: OffersProps) {
|
||||
const offers = use(products);
|
||||
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;
|
||||
}
|
||||
13
src/components/domains/additional-purchases/index.ts
Normal file
@ -0,0 +1,13 @@
|
||||
export { default as AddConsultantButton } from "./AddConsultantButton/AddConsultantButton";
|
||||
export { default as AddGuidesButton } from "./AddGuidesButton/AddGuidesButton";
|
||||
export { default as Caution } from "./Caution/Caution";
|
||||
export {
|
||||
default as ConsultationTable,
|
||||
ConsultationTableSkeleton,
|
||||
} from "./ConsultationTable/ConsultationTable";
|
||||
export { default as Offer } from "./Offer/Offer";
|
||||
export { default as Offers, OffersSkeleton } from "./Offers/Offers";
|
||||
export {
|
||||
ProductSelectionProvider,
|
||||
useProductSelection,
|
||||
} from "./ProductSelectionContext";
|
||||
@ -1,17 +1,12 @@
|
||||
import { ReactNode } from "react";
|
||||
import clsx from "clsx";
|
||||
|
||||
import styles from "./Card.module.scss";
|
||||
|
||||
type CardProps = {
|
||||
children: ReactNode;
|
||||
className?: string;
|
||||
style?: React.CSSProperties;
|
||||
};
|
||||
type CardProps = React.HTMLAttributes<HTMLDivElement>;
|
||||
|
||||
export default function Card({ children, className, style }: CardProps) {
|
||||
export default function Card({ children, className, ...props }: CardProps) {
|
||||
return (
|
||||
<div className={clsx(styles.card, className)} style={style}>
|
||||
<div className={clsx(styles.card, className)} {...props}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
|
||||
@ -5,6 +5,11 @@
|
||||
text-align: center;
|
||||
text-align: -webkit-center;
|
||||
|
||||
& > * {
|
||||
position: relative;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.gradientBlur {
|
||||
position: absolute;
|
||||
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,
|
||||
CheckoutResponse,
|
||||
CheckoutResponseSchema,
|
||||
SingleCheckoutRequest,
|
||||
SingleCheckoutResponse,
|
||||
SingleCheckoutResponseSchema,
|
||||
} from "./types";
|
||||
|
||||
export async function createPaymentCheckout(payload: CheckoutRequest) {
|
||||
@ -13,3 +16,16 @@ export async function createPaymentCheckout(payload: CheckoutRequest) {
|
||||
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(),
|
||||
});
|
||||
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 ?? [])
|
||||
);
|
||||
61
src/entities/session/funnel/types.ts
Normal file
@ -0,0 +1,61 @@
|
||||
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(),
|
||||
});
|
||||
|
||||
export const FunnelSchema = z.object({
|
||||
currency: z.nativeEnum(Currency),
|
||||
funnel: z.nativeEnum(ELocalesPlacement),
|
||||
locale: z.string(),
|
||||
payment: z.record(z.string(), FunnelPaymentPlacementSchema.nullable()),
|
||||
});
|
||||
|
||||
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>;
|
||||
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"]),
|
||||
subscriptions: () => createRoute(["payment", "subscriptions"], ROOT_ROUTE_V3),
|
||||
paymentCheckout: () => createRoute(["payment", "checkout"], ROOT_ROUTE_V2),
|
||||
paymentSingleCheckout: () => createRoute(["payment", "checkout"]),
|
||||
usersMe: () => createRoute(["users", "me"], ROOT_ROUTE),
|
||||
compatibilityActionFields: (id: string) =>
|
||||
createRoute(["dashboard", "compatibility-actions", id, "fields"]),
|
||||
@ -28,4 +29,7 @@ export const API_ROUTES = {
|
||||
["payment", "subscriptions", subscriptionId, action],
|
||||
ROOT_ROUTE_V3
|
||||
),
|
||||
|
||||
// session
|
||||
funnel: () => createRoute(["session", "funnel"], ROOT_ROUTE_V2),
|
||||
};
|
||||
|
||||
@ -63,6 +63,10 @@ export const ROUTES = {
|
||||
// Chat
|
||||
chat: () => createRoute(["chat"]),
|
||||
|
||||
// Additional Purchases
|
||||
addConsultant: () => createRoute(["add-consultant"]),
|
||||
addGuides: () => createRoute(["add-guides"]),
|
||||
|
||||
// // Compatibility
|
||||
// compatibilities: () => createRoute(["compatibilities"]),
|
||||
|
||||
|
||||
@ -60,3 +60,26 @@ export type ActionResponse<T> = {
|
||||
data: T | 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";
|
||||
|
||||