feat(chat): prompt before credit top up

This commit is contained in:
2026-07-01 13:01:35 +08:00
parent abc0faf197
commit d1ccf3631e
5 changed files with 237 additions and 35 deletions
+1
View File
@@ -16,6 +16,7 @@ export * from "./external-browser-dialog";
export * from "./fullscreen-image-viewer";
export * from "./history-unlock-dialog";
export * from "./image-bubble";
export * from "./insufficient-credits-dialog";
export * from "./language-dialog";
export * from "./lottie-message-bubble";
export * from "./message-avatar";
@@ -0,0 +1,102 @@
.overlay {
position: fixed;
inset: 0;
z-index: 220;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
background: rgba(0, 0, 0, 0.52);
}
.dialog {
width: 100%;
max-width: var(--pwa-install-dialog-max-width, 360px);
padding: 24px 18px 18px;
text-align: center;
background: var(--color-page-background, #ffffff);
border: 1px solid rgba(246, 87, 160, 0.16);
border-radius: 36px;
box-shadow: 0 18px 46px rgba(38, 18, 31, 0.18);
}
.title {
margin: 0 0 10px;
color: var(--color-text-foreground, #171717);
font-size: var(--font-size-22, 22px);
font-weight: 700;
line-height: 1.2;
}
.content {
margin: 0 12px 18px;
color: #393939;
font-size: var(--font-size-lg, 16px);
line-height: 1.5;
}
.creditList {
display: grid;
gap: 8px;
margin: 0 0 18px;
padding: 12px;
background: #fff4f9;
border-radius: 22px;
}
.creditItem {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
color: #4a3b43;
font-size: var(--font-size-md, 14px);
line-height: 1.3;
}
.creditItem dt {
margin: 0;
font-weight: 500;
}
.creditItem dd {
margin: 0;
color: #f657a0;
font-size: var(--font-size-lg, 16px);
font-weight: 800;
}
.actions {
display: flex;
gap: var(--spacing-md, 12px);
width: 100%;
}
.button {
flex: 1 1 auto;
height: var(--pwa-button-height, 44px);
border: 0;
border-radius: var(--radius-bottom-sheet, 28px);
font-size: var(--font-size-lg, 16px);
font-weight: 700;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
}
.secondary {
color: var(--color-page-background, #ffffff);
background: var(--color-text-secondary, #9e9e9e);
}
.primary {
color: var(--color-page-background, #ffffff);
background: linear-gradient(90deg, #ff67e0 0%, #ff52a2 100%);
box-shadow: 0 6px 14px rgba(246, 87, 160, 0.28);
}
.button:focus-visible {
outline: 2px solid #f657a0;
outline-offset: 3px;
}
@@ -0,0 +1,77 @@
"use client";
import styles from "./insufficient-credits-dialog.module.css";
export interface InsufficientCreditsDialogProps {
open: boolean;
creditBalance: number;
requiredCredits: number;
shortfallCredits: number;
onClose: () => void;
onConfirm: () => void;
}
export function InsufficientCreditsDialog({
open,
creditBalance,
requiredCredits,
shortfallCredits,
onClose,
onConfirm,
}: InsufficientCreditsDialogProps) {
if (!open) return null;
const showCreditDetail = requiredCredits > 0 || shortfallCredits > 0;
return (
<div
className={styles.overlay}
role="dialog"
aria-modal="true"
aria-labelledby="insufficient-credits-title"
>
<div className={styles.dialog}>
<h2 id="insufficient-credits-title" className={styles.title}>
Not enough credits
</h2>
<p className={styles.content}>
Top up your credits to unlock this message and keep the moment going.
</p>
{showCreditDetail ? (
<dl className={styles.creditList}>
<div className={styles.creditItem}>
<dt>Balance</dt>
<dd>{creditBalance}</dd>
</div>
<div className={styles.creditItem}>
<dt>Required</dt>
<dd>{requiredCredits}</dd>
</div>
<div className={styles.creditItem}>
<dt>Still needed</dt>
<dd>{shortfallCredits}</dd>
</div>
</dl>
) : null}
<div className={styles.actions}>
<button
type="button"
className={`${styles.button} ${styles.secondary}`}
onClick={onClose}
>
Later
</button>
<button
type="button"
className={`${styles.button} ${styles.primary}`}
onClick={onConfirm}
>
Top up now
</button>
</div>
</div>
</div>
);
}