Browse Source

feat: update finding match page layout and styles

- Adjusted dimensions of the image container in FindingMatchPage.
- Modified the submit path logic in Intro component to handle new case statuses.
- Changed button to link in NewMatchPage for profile viewing and added a locked profile indicator.
- Enhanced NewMatchProfilePage with mutation for responding to marriage cases and improved button states.
- Updated QuestionsListPage to change text size for optional info prompt.
- Refactored RequestAcceptedPage to include subscription handling and improved layout.
- Added SubscriptionRequiredSheet for subscription prompts and payment handling.
- Implemented useHabcoinPayment hook for managing Habcoin payments.
- Introduced new RequestSentPage for displaying request status.
- Added new SVG asset for request sent confirmation.
master
sina_sajjadi 2 months ago
parent
commit
21f94bd522
  1. 21
      public/assets/images/Group 15978804fdasf68.svg
  2. 1
      src/app/[lang]/request-sent/page.tsx
  3. 2
      src/app/finding-match/page.tsx
  4. 6
      src/app/intro/page.tsx
  5. 28
      src/app/new-match/page.tsx
  6. 56
      src/app/new-match/profile/page.tsx
  7. 2
      src/app/questions-list/page.tsx
  8. 113
      src/app/request-accepted/page.tsx
  9. 76
      src/app/request-sent/page.tsx
  10. 2
      src/components/ui/call-result-sheet.tsx
  11. 68
      src/components/ui/dismiss-reason-sheet.tsx
  12. 81
      src/components/ui/subscription-required-sheet.tsx
  13. 5
      src/hooks/marriage/types.ts
  14. 85
      src/hooks/marriage/use-habcoin-payment.ts
  15. 8
      src/hooks/marriage/use-profile-main.ts

21
public/assets/images/Group 15978804fdasf68.svg
File diff suppressed because it is too large
View File

1
src/app/[lang]/request-sent/page.tsx

@ -0,0 +1 @@
export { default } from "@/app/request-sent/page";

2
src/app/finding-match/page.tsx

@ -31,7 +31,7 @@ export default function FindingMatchPage() {
</header>
<section className="flex flex-1 flex-col items-center mt-32">
<div className="relative h-[120px] w-[124px]" aria-hidden="true">
<div className="relative h-[124px] w-[130px]" aria-hidden="true">
<Image
src="/assets/images/Group 159788fd0467.svg"
alt=""

6
src/app/intro/page.tsx

@ -11,7 +11,11 @@ export default function Intro() {
const { dictionary: t, locale } = useI18n();
const { data: profile } = useMarriageProfileQuery();
const submitPath =
profile?.status === "pending_onboarding"
profile?.active_case?.status === "female_accepted"
? "/request-accepted"
: profile?.active_case?.status === "male_accepted"
? "/request-sent"
: profile?.status === "pending_onboarding"
? "/rules"
: profile?.status === "pending_info"
? "/questions-list"

28
src/app/new-match/page.tsx

@ -2,8 +2,7 @@
import Image from "next/image";
import { useMemo } from "react";
import { FaBell } from "react-icons/fa6";
import Button from "@/components/ui/button";
import { FaBell, FaLock } from "react-icons/fa6";
import { PageBackground } from "@/components/utils/page-background";
import type {
MarriageField,
@ -240,12 +239,12 @@ export default function NewMatchPage() {
))}
</div>
<Button
className="mt-[15px] rounded-[7px] border-none bg-white bg-none py-[12px] text-[#F0445B]! shadow-none"
<a
href="/new-match/profile"
className="mt-[15px] inline-flex w-full items-center justify-center rounded-[7px] border-none bg-white py-[12px] text-[16px] font-semibold text-[#F0445B] no-underline shadow-none"
>
View Profile
</Button>
</a>
</>
) : (
<p className="py-8 text-[13px] font-semibold">
@ -283,14 +282,27 @@ export default function NewMatchPage() {
</span>
</div>
<Button
className="w-auto rounded-[9px] border-none bg-[#EBEDF0] bg-none px-5 py-[13px] text-[#111111]! shadow-none"
<a
href="/questions-list"
className="inline-flex w-auto items-center justify-center rounded-[9px] border-none bg-[#EBEDF0] px-5 py-[13px] text-[16px] font-semibold text-[#111111] no-underline shadow-none"
>
{t.findingMatch.getAdvisor}
</Button>
</a>
</div>
</section>
<div className="mt-auto px-[12px] pt-6">
<div
className="flex cursor-not-allowed py-3.5 w-full items-center justify-center rounded-[11px] border-none bg-[#DBDBDB] px-6 text-[#747474] no-underline shadow-none"
>
<span className="flex items-center gap-1">
<FaLock className="size-6 shrink-0 text-[#747474]" />
<span className="leading-none font-semibold tracking-[-0.03em]">
Profile locked
</span>
</span>
</div>
</div>
</main>
</>
);

56
src/app/new-match/profile/page.tsx

@ -9,7 +9,11 @@ import InformationSheet from "@/components/ui/information-sheet";
import NavigationButton from "@/components/ui/navigation-button";
import StickyHeader from "@/components/ui/sticky-header";
import { PageBackground } from "@/components/utils/page-background";
import type { MarriageField, MarriageFieldValue } from "@/hooks/marriage/types";
import {
type MarriageField,
type MarriageFieldValue,
} from "@/hooks/marriage/types";
import { useRespondToMarriageCaseMutation } from "@/hooks/marriage/use-case-respond";
import { useMarriageProfileQuery } from "@/hooks/marriage/use-profile-main";
import { localizePath } from "@/i18n/config";
import { useI18n } from "@/i18n/provider";
@ -66,6 +70,20 @@ export default function NewMatchProfilePage() {
const [isDismissReasonSheetOpen, setIsDismissReasonSheetOpen] =
useState(false);
const { data: profile } = useMarriageProfileQuery();
const caseId = profile?.active_case?.case_id;
const isMaleAccepted = profile?.active_case?.status === "male_accepted";
const respondMutation = useRespondToMarriageCaseMutation(caseId ?? "", {
onSuccess: async (_, variables) => {
if (variables.action === "accept") {
router.push(localizePath("/request-sent", locale));
return;
}
router.push(localizePath("/candidate-contact", locale));
},
});
const isSubmitting = respondMutation.isPending;
return (
<>
@ -82,9 +100,18 @@ export default function NewMatchProfilePage() {
</Button>
<Button
className="py-[18px]"
onClick={() => {
disabled={!caseId || isSubmitting || isMaleAccepted}
onClick={async () => {
close();
router.push(localizePath("/request-accepted", locale));
if (!caseId) {
return;
}
if (isMaleAccepted) {
return;
}
await respondMutation.mutateAsync({ action: "accept" });
}}
>
{t.common.confirm}
@ -121,8 +148,15 @@ export default function NewMatchProfilePage() {
{isDismissReasonSheetOpen ? (
<DismissReasonSheet
onClose={() => setIsDismissReasonSheetOpen(false)}
onSubmit={() => {
router.push(localizePath("/candidate-contact", locale));
onSubmit={async (reason) => {
if (!caseId) {
return;
}
await respondMutation.mutateAsync({
action: "reject",
custom_note: reason,
});
}}
/>
) : null}
@ -178,6 +212,7 @@ export default function NewMatchProfilePage() {
<div className="flex gap-3">
<button
type="button"
disabled={!caseId || isSubmitting || isMaleAccepted}
onClick={() => setIsRejectSheetOpen(true)}
className="inline-flex w-1/3 items-center justify-center rounded-[12px] border border-[#BFBFBF] bg-white px-4 py-[13px] text-[16px] font-semibold text-[#9A9A9A]"
>
@ -185,8 +220,15 @@ export default function NewMatchProfilePage() {
</button>
<button
type="button"
onClick={() => setIsRequestSheetOpen(true)}
className="inline-flex w-2/3 whitespace-nowrap items-center justify-center gap-1 rounded-[12px] bg-[#F0445B] px-4 py-[13px] text-[16px] font-semibold text-white shadow-[0_8px_16px_rgba(240,68,91,0.24)]"
disabled={!caseId || isSubmitting || isMaleAccepted}
onClick={() => {
if (isMaleAccepted) {
return;
}
setIsRequestSheetOpen(true);
}}
className="inline-flex w-2/3 whitespace-nowrap items-center justify-center gap-1 rounded-[12px] bg-[#F0445B] px-4 py-[13px] text-[16px] font-semibold text-white shadow-[0_8px_16px_rgba(240,68,91,0.24)] disabled:cursor-not-allowed disabled:opacity-50"
>
<Image
src="/assets/images/Icfdason.svg"

2
src/app/questions-list/page.tsx

@ -78,7 +78,7 @@ export default function QuestionsListPage() {
icon="warning"
title={t.questions.optionalInfoPromptTitle}
description={
<p className="px-0.5 text-[16px] leading-[1.45] text-[#2D2D2D]">
<p className="px-0.5 text-sm leading-[1.45] text-[#2D2D2D]">
{t.questions.optionalInfoPromptDescription}
</p>
}

113
src/app/request-accepted/page.tsx

@ -1,43 +1,75 @@
"use client";
import Image from "next/image";
import Link from "next/link";
import { useRouter } from "next/navigation";
import Button from "@/components/ui/button";
import { useState } from "react";
import NavigationButton from "@/components/ui/navigation-button";
import SubscriptionRequiredSheet from "@/components/ui/subscription-required-sheet";
import { PageBackground } from "@/components/utils/page-background";
import {
extractHabcoinPaymentUrl,
useHabcoinPaymentMutation,
} from "@/hooks/marriage/use-habcoin-payment";
import { useMarriageProfileQuery } from "@/hooks/marriage/use-profile-main";
import { localizePath } from "@/i18n/config";
import { useI18n } from "@/i18n/provider";
export default function RequestAcceptedPage() {
const { dictionary: t, locale } = useI18n();
const { locale } = useI18n();
const router = useRouter();
const [isSubscriptionSheetOpen, setIsSubscriptionSheetOpen] = useState(false);
const profileHref = localizePath("/new-match/profile", locale);
const { data: profile } = useMarriageProfileQuery();
const recommendedPlanId = profile?.recommended_plan?.id;
const paymentMutation = useHabcoinPaymentMutation();
const handlePayment = async () => {
if (!recommendedPlanId || paymentMutation.isPending) {
return;
}
try {
const paymentResponse =
await paymentMutation.mutateAsync(recommendedPlanId);
const paymentUrl = extractHabcoinPaymentUrl(paymentResponse);
if (paymentUrl) {
window.location.assign(paymentUrl);
return;
}
router.push(profileHref);
} catch (error) {
console.error("Habcoin payment request failed", error);
}
};
return (
<>
<PageBackground />
{isSubscriptionSheetOpen ? (
<SubscriptionRequiredSheet
onClose={() => setIsSubscriptionSheetOpen(false)}
onPayment={handlePayment}
isPaymentPending={!recommendedPlanId || paymentMutation.isPending}
/>
) : null}
<main className="-mx-[17px] flex min-h-screen flex-col px-[23px] pt-7 pb-10 text-center">
<header className="-mx-[6px] flex items-center justify-between">
<NavigationButton icon="back" />
<h1 className="font-faminela">{t.common.appName}</h1>
<NavigationButton icon="support" iconLabel={t.common.support} />
<h1 className="font-faminela">Habib Marriage</h1>
<NavigationButton icon="support" iconLabel="Support" />
</header>
<div className="flex flex-1 flex-col justify-end gap-20 pt-[26px]">
<div className="flex flex-1 flex-col justify-between gap-20 pt-[109px]">
<section className="flex flex-col items-center">
<div className="relative isolate flex items-center justify-center">
<Image
src="/assets/images/Union.svg"
alt=""
width={375}
height={813}
aria-hidden="true"
className="pointer-events-none absolute top-1/2 left-1/2 -z-10 max-w-none -translate-x-1/2 -translate-y-1/2"
/>
<Image
src="/assets/images/Group 1597880468.svg"
alt={t.requestAccepted.imageAlt}
src="/assets/images/Group 15978804fdasf68.svg"
alt="Request sent"
width={131}
height={125}
priority
@ -46,47 +78,54 @@ export default function RequestAcceptedPage() {
</div>
<h1 className="mt-11 text-[22px] leading-none font-black tracking-[0.02em] text-[#171717] uppercase">
{t.requestAccepted.title}
REQUEST ACCEPTED
</h1>
<p className="mt-4 max-w-[315px] text-[16px] leading-[1.45] font-semibold text-[#777777]">
{t.requestAccepted.description}
You can now view their family&apos;s contact details and arrange
further steps.
</p>
<div className="mt-9 w-full max-w-[212px]">
<Button
className="border-none bg-[linear-gradient(180deg,#FF7387_0%,#F0445B_100%)] py-[18px] shadow-[0_14px_32px_rgba(240,68,91,0.3)]"
onClick={() =>
router.push(localizePath("/candidate-contact", locale))
}
<div className="flex mt-9 w-full justify-center gap-4">
<Link href={profileHref} className="max-w-[212px]">
<div className="bg-[#F5F5F5] px-4 py-2 rounded-[15px] shadow text-sm text-center font-semibold text-[#36363C]">
Match Profile
</div>
</Link>
<button
type="button"
onClick={() => setIsSubscriptionSheetOpen(true)}
className="max-w-[212px] appearance-none border-0 bg-transparent p-0 text-left"
>
{t.requestAccepted.viewContact}
</Button>
<div className="bg-linear-180 from-[#FE6F82] to-[#E03950] px-4 py-2 rounded-[15px] shadow text-sm text-center font-semibold text-[#fff] shadow-md shadow-[#F2596E]/60">
View Contact
</div>
</button>
</div>
</section>
<div className="space-y-8">
<div className="rounded-[12px] border border-[#F0445B] bg-[#F0445B]/10 px-3 py-2.5 text-xs leading-4 font-medium text-[#F0445B]">
{t.requestAccepted.penalty}
<div className="border border-[#F0445B] bg-[#F0445B]/10 rounded-xl mt-4">
<p className="text-[#F0445B] text-xs font-semibold py-2.5 px-3.5">
Please note: if you do not make contact within 2 days, a penalty
may apply
</p>
</div>
</section>
<div className="space-y-8">
<section className="flex flex-col items-center text-center">
<div className="flex items-center gap-1">
<div className="flex items-center justify-center w-full gap-1 rounded-[11px] bg-[#DBDBDB] py-3.5">
<Image
src={"/assets/images/material-symbols_lock.svg"}
src="/assets/images/material-symbols_lock.svg"
width={24}
height={24}
alt="lock"
/>
<h2 className="text-[17px] leading-none font-semibold text-[#747474]">
{t.requestAccepted.profileLocked}
Profile is locked
</h2>
</div>
<p className="mt-1 text-[10px] font-semibold text-[#8B8B8B]">
{t.requestAccepted.lockedDescription}
</p>
</section>
</div>
</div>

76
src/app/request-sent/page.tsx

@ -0,0 +1,76 @@
"use client";
import Image from "next/image";
import { useRouter } from "next/navigation";
import Button from "@/components/ui/button";
import NavigationButton from "@/components/ui/navigation-button";
import { PageBackground } from "@/components/utils/page-background";
import { localizePath } from "@/i18n/config";
import { useI18n } from "@/i18n/provider";
import Link from "next/link";
export default function RequestSentPage() {
const { locale } = useI18n();
const router = useRouter();
return (
<>
<PageBackground />
<main className="-mx-[17px] flex min-h-screen flex-col px-[23px] pt-7 pb-10 text-center">
<header className="-mx-[6px] flex items-center justify-between">
<NavigationButton icon="back" />
<h1 className="font-faminela">Habib Marriage</h1>
<NavigationButton icon="support" iconLabel="Support" />
</header>
<div className="flex flex-1 flex-col justify-between gap-20 pt-[109px]">
<section className="flex flex-col items-center">
<div className="relative isolate flex items-center justify-center">
<Image
src="/assets/images/Group 15978804fdasf68.svg"
alt="Request sent"
width={131}
height={125}
priority
className="relative z-10"
/>
</div>
<h1 className="mt-11 text-[22px] leading-none font-black tracking-[0.02em] text-[#171717] uppercase">
Request Sent
</h1>
<p className="mt-4 max-w-[315px] text-[16px] leading-[1.45] font-semibold text-[#777777]">
We will propose marriage on your behalf. If they accept, their contact details will be shared with you.
</p>
<Link href={"/new-match/profile"} className="mt-9 w-full max-w-[212px]">
<div className="bg-[#F5F5F5] px-4 py-2 rounded-[15px] shadow text-sm text-center font-semibold text-[#36363C]">
Match Profile
</div>
</Link >
</section>
<div className="space-y-8">
<section className="flex flex-col items-center text-center">
<div className="flex items-center justify-center py-3.5 rounded-[11px] gap-1 w-full bg-[#DBDBDB]">
<Image
src={"/assets/images/material-symbols_lock.svg"}
width={24}
height={24}
alt="lock"
/>
<h2 className="text-[17px] leading-none font-semibold text-[#747474]">
Profile is locked
</h2>
</div>
</section>
</div>
</div>
</main>
</>
);
}

2
src/components/ui/call-result-sheet.tsx

@ -9,7 +9,7 @@ const EXIT_ANIMATION_MS = 220;
export type CallResultSheetProps = Omit<
HTMLAttributes<HTMLDivElement>,
"title"
"title" | "onSubmit"
> & {
closeOnOutside?: boolean;
onClose?: () => void;

68
src/components/ui/dismiss-reason-sheet.tsx

@ -9,7 +9,7 @@ const EXIT_ANIMATION_MS = 220;
export type DismissReasonSheetProps = Omit<
HTMLAttributes<HTMLDivElement>,
"title"
"title" | "onSubmit"
> & {
closeOnOutside?: boolean;
onClose?: () => void;
@ -29,7 +29,7 @@ export function DismissReasonSheet({
const [isVisible, setIsVisible] = useState(true);
const [isEntering, setIsEntering] = useState(true);
const [isClosing, setIsClosing] = useState(false);
const [selectedReason, setSelectedReason] = useState(options[0]);
const [selectedReason, setSelectedReason] = useState<string>(options[0]);
const [reasonText, setReasonText] = useState("");
const closeSheet = () => {
@ -146,49 +146,55 @@ export function DismissReasonSheet({
const showTextArea = option === options[options.length - 1];
return (
<button
<div
key={option}
type="button"
className={[
"flex w-full items-start gap-3 rounded-[14px] bg-[#ECECEC] px-[14px] py-[18px] text-left",
"w-full rounded-[14px] bg-[#ECECEC] px-[14px] py-[18px]",
checked ? "text-[#171717]" : "text-[#7B7B7B]",
]
.filter(Boolean)
.join(" ")}
onClick={() => setSelectedReason(option)}
>
<span
aria-hidden="true"
<button
type="button"
className={[
"mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-full border",
checked ? "border-[#F0445B]" : "border-[#9E9E9E]",
"flex w-full items-start gap-3 text-left",
checked ? "text-[#171717]" : "text-[#7B7B7B]",
]
.filter(Boolean)
.join(" ")}
onClick={() => setSelectedReason(option)}
>
{checked ? (
<span className="h-3 w-3 rounded-full bg-[#F0445B]" />
) : null}
</span>
<span className="flex min-w-0 flex-1 flex-col">
<span className="text-[16px] leading-[1.2] font-semibold">
{option}
<span
aria-hidden="true"
className={[
"mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-full border",
checked ? "border-[#F0445B]" : "border-[#9E9E9E]",
]
.filter(Boolean)
.join(" ")}
>
{checked ? (
<span className="h-3 w-3 rounded-full bg-[#F0445B]" />
) : null}
</span>
{checked && showTextArea ? (
<textarea
className="mt-4 min-h-[143px] w-full resize-none rounded-[16px] border border-[#454545] bg-transparent px-3 py-3 text-[16px] text-[#171717] outline-none placeholder:text-[#AAAAAA]"
placeholder={t.sheets.dismissPlaceholder}
value={reasonText}
onChange={(event) =>
setReasonText(event.target.value)
}
onClick={(event) => event.stopPropagation()}
/>
) : null}
</span>
</button>
<span className="min-w-0 flex-1">
<span className="text-[16px] leading-[1.2] font-semibold">
{option}
</span>
</span>
</button>
{checked && showTextArea ? (
<textarea
className="mt-3 h-[125px] w-full resize-none rounded-[16px] border border-[#454545] bg-transparent px-3 py-3 text-[16px] text-[#171717] outline-none placeholder:text-[#AAAAAA]"
placeholder={t.sheets.dismissPlaceholder}
value={reasonText}
onChange={(event) => setReasonText(event.target.value)}
/>
) : null}
</div>
);
})}
</div>

81
src/components/ui/subscription-required-sheet.tsx

@ -0,0 +1,81 @@
"use client";
import Image from "next/image";
import InformationSheet from "@/components/ui/information-sheet";
type SubscriptionRequiredSheetProps = {
onClose: () => void;
onPayment: () => void;
isPaymentPending?: boolean;
};
export function SubscriptionRequiredSheet({
onClose,
onPayment,
isPaymentPending = false,
}: SubscriptionRequiredSheetProps) {
return (
<InformationSheet
icon="coin"
title="Subscription required"
description={
<div className="space-y-4 text-left">
<p className="text-sm text-center leading-[1.45] font-medium text-[#2B2B2B]">
To view profiles, you need a subscription. Each subscription
includes up to{" "}
<span className="font-bold underline decoration-[1.5px] underline-offset-2">
3
</span>{" "}
matches.
</p>
<div className="rounded-[12px] border border-[#FF4F67] bg-[#FFECEF] px-3.5 py-2.5 text-center">
<p className="text-xs leading-[1.45] font-semibold text-[#FF4F67]">
To view profiles, a subscription is required. This helps cover our
support and matching services and applies only to male users
</p>
</div>
</div>
}
onClose={onClose}
buttons={({ close }) => (
<div className="grid w-full grid-cols-[1fr_2fr] gap-3">
<button
type="button"
className="appearance-none border-0 bg-transparent p-0 text-left"
onClick={close}
>
<div className="inline-flex w-full items-center justify-center rounded-[18px] border border-[#9A9A9A] bg-[#F7F7F7] px-4 py-[18px] text-[16px] font-bold text-[#8B8B8B] shadow-[inset_0_1px_0_rgba(255,255,255,0.8)] transition-opacity active:opacity-90">
Back
</div>
</button>
<button
type="button"
disabled={isPaymentPending}
className="appearance-none border-0 bg-transparent p-0 text-left disabled:cursor-not-allowed disabled:opacity-70"
onClick={onPayment}
>
<div className="inline-flex w-full items-center justify-center gap-3 rounded-[18px] bg-[#F0445B] px-4 py-[16px] text-[16px] font-semibold text-white shadow-[0_10px_18px_rgba(240,68,91,0.28)] transition-opacity active:opacity-90">
<span>Payment</span>
<span className="inline-flex items-center gap-1 rounded-full bg-[#E43B51] p-1.5 text-xs font-semibold leading-none text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.12)]">
<Image
src="/assets/images/Inner Plugdsain Iframe.svg"
alt=""
aria-hidden="true"
width={18}
height={18}
className="shrink-0"
/>
<span>50 Habib Coin</span>
</span>
</div>
</button>
</div>
)}
/>
);
}
export default SubscriptionRequiredSheet;

5
src/hooks/marriage/types.ts

@ -17,6 +17,7 @@ export type MarriageProfileStatus =
export type MarriageCaseStatus =
| "introduced"
| "male_accepted"
| "female_accepted"
| "male_rejected"
| "female_rejected"
| "payment_pending"
@ -79,10 +80,12 @@ export type MarriageProfile = {
is_ready_for_match: boolean;
active_case: MarriageActiveCase | null;
needs_subscription: boolean;
recommended_plan?: MarriageRecommendedPlan | null;
recommended_plan: MarriageRecommendedPlan | null;
match_summary: MarriageMatchSummary | null;
};
export type MarriageProfileResponse = MarriageProfile;
export type UpdateMarriageProfileBasicPayload = {
gender: MarriageGender;
is_registering_for_self: boolean;

85
src/hooks/marriage/use-habcoin-payment.ts

@ -0,0 +1,85 @@
"use client";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { http } from "@/lib/http";
import type { MutationOptions } from "./options";
import { marriageQueryKeys } from "./query-keys";
const HABCOIN_PAY_SERVICE = "marriagesubscriptionplan" as const;
type HabcoinPaymentResponse = unknown;
function getSecurityToken() {
const token = process.env.NEXT_PUBLIC_SECURITY_KEY;
if (!token) {
throw new Error("NEXT_PUBLIC_SECURITY_KEY is required");
}
return token;
}
export function extractHabcoinPaymentUrl(response: HabcoinPaymentResponse) {
if (typeof response === "string") {
const trimmed = response.trim();
return /^(https?:\/\/|\/)/i.test(trimmed) ? trimmed : null;
}
if (!response || typeof response !== "object") {
return null;
}
const record = response as Record<string, unknown>;
const candidates = [
record.url,
record.payment_url,
record.redirect_url,
record.checkout_url,
record.payment_link,
record.link,
record.href,
];
for (const candidate of candidates) {
if (typeof candidate === "string" && candidate.trim()) {
return candidate.trim();
}
}
if (record.data && typeof record.data === "object") {
return extractHabcoinPaymentUrl(record.data);
}
return null;
}
export async function getHabcoinPayment(objectId: number) {
const { data } = await http.get<HabcoinPaymentResponse>("/habcoin/pay/", {
params: {
token: getSecurityToken(),
service: HABCOIN_PAY_SERVICE,
object_id: objectId,
},
});
return data;
}
export function useHabcoinPaymentMutation(
options?: MutationOptions<HabcoinPaymentResponse, number>,
) {
const queryClient = useQueryClient();
return useMutation({
...options,
mutationFn: getHabcoinPayment,
onSuccess: async (data, variables, onMutateResult, context) => {
await queryClient.invalidateQueries({
queryKey: marriageQueryKeys.profile(),
});
await options?.onSuccess?.(data, variables, onMutateResult, context);
},
});
}

8
src/hooks/marriage/use-profile-main.ts

@ -4,18 +4,18 @@ import { useQuery } from "@tanstack/react-query";
import { http } from "@/lib/http";
import type { QueryOptions } from "./options";
import { marriageQueryKeys } from "./query-keys";
import type { MarriageProfile } from "./types";
import type { MarriageProfileResponse } from "./types";
export async function getMarriageProfile() {
const { data } = await http.get<MarriageProfile>(
const { data } = await http.get<MarriageProfileResponse>(
"/api/marriage/profile/main/",
);
return data;
}
export function useMarriageProfileQuery<TData = MarriageProfile>(
options?: QueryOptions<MarriageProfile, TData>,
export function useMarriageProfileQuery<TData = MarriageProfileResponse>(
options?: QueryOptions<MarriageProfileResponse, TData>,
) {
return useQuery({
...options,

Loading…
Cancel
Save