Merge remote-tracking branch 'upstream/main'
This commit is contained in:
@@ -73,6 +73,14 @@
|
||||
"referrerUserId": "Referrer User ID",
|
||||
"remove": "Remove",
|
||||
"resetLogs": "Reset Logs",
|
||||
"resetTraffic": "Reset Traffic",
|
||||
"toggleStatus": "Toggle Status",
|
||||
"resetSubscriptionToken": "Reset Token",
|
||||
"resetSubscriptionTokenDescription": "This will reset the subscription token. Old links will become invalid.",
|
||||
"resetSubscriptionTraffic": "Reset Traffic",
|
||||
"resetSubscriptionTrafficDescription": "This will reset the subscription traffic counters.",
|
||||
"toggleSubscriptionStatus": "Toggle Status",
|
||||
"toggleSubscriptionStatusDescription": "This will toggle the subscription status.",
|
||||
"resetTime": "Reset Time",
|
||||
"resetToken": "Reset Subscription Address",
|
||||
"resetTokenDescription": "This will reset the subscription address and regenerate a new token.",
|
||||
|
||||
@@ -73,6 +73,14 @@
|
||||
"referrerUserId": "推荐人用户 ID",
|
||||
"remove": "移除",
|
||||
"resetLogs": "重置日志",
|
||||
"resetTraffic": "重置流量",
|
||||
"toggleStatus": "切换状态",
|
||||
"resetSubscriptionToken": "重置令牌",
|
||||
"resetSubscriptionTokenDescription": "将重置订阅令牌,旧订阅链接会失效。",
|
||||
"resetSubscriptionTraffic": "重置流量",
|
||||
"resetSubscriptionTrafficDescription": "将重置该订阅的流量统计。",
|
||||
"toggleSubscriptionStatus": "切换状态",
|
||||
"toggleSubscriptionStatusDescription": "将切换该订阅的启用/停用状态。",
|
||||
"resetTime": "重置时间",
|
||||
"resetToken": "重置订阅地址",
|
||||
"resetTokenDescription": "这将重置订阅地址并重新生成新的令牌。",
|
||||
|
||||
@@ -77,6 +77,7 @@ const defaultValues = {
|
||||
purchase_with_discount: false,
|
||||
reset_cycle: 0,
|
||||
renewal_reset: false,
|
||||
show_original_price: false,
|
||||
deduction_mode: "auto",
|
||||
};
|
||||
|
||||
@@ -837,6 +838,41 @@ export default function SubscribeForm<T extends Record<string, any>>({
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="show_original_price"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="space-y-0.5">
|
||||
<FormLabel>
|
||||
{t(
|
||||
"form.showOriginalPrice",
|
||||
"Show Original Price"
|
||||
)}
|
||||
</FormLabel>
|
||||
<FormDescription>
|
||||
{t(
|
||||
"form.showOriginalPriceDescription",
|
||||
"Display original price in the storefront"
|
||||
)}
|
||||
</FormDescription>
|
||||
</div>
|
||||
<FormControl>
|
||||
<Switch
|
||||
checked={!!field.value}
|
||||
onCheckedChange={(value) =>
|
||||
form.setValue(field.name, value)
|
||||
}
|
||||
/>
|
||||
</FormControl>
|
||||
</div>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="allow_deduction"
|
||||
|
||||
@@ -37,7 +37,7 @@ const verifySchema = z.object({
|
||||
turnstile_secret: z.string().optional(),
|
||||
enable_register_verify: z.boolean().optional(),
|
||||
enable_login_verify: z.boolean().optional(),
|
||||
enable_password_verify: z.boolean().optional(),
|
||||
enable_reset_password_verify: z.boolean().optional(),
|
||||
});
|
||||
|
||||
type VerifyFormData = z.infer<typeof verifySchema>;
|
||||
@@ -63,7 +63,7 @@ export default function VerifyConfig() {
|
||||
turnstile_secret: "",
|
||||
enable_register_verify: false,
|
||||
enable_login_verify: false,
|
||||
enable_password_verify: false,
|
||||
enable_reset_password_verify: false,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -243,7 +243,7 @@ export default function VerifyConfig() {
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="enable_password_verify"
|
||||
name="enable_reset_password_verify"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>
|
||||
|
||||
@@ -69,7 +69,11 @@ export default function User() {
|
||||
action={ref}
|
||||
actions={{
|
||||
render: (row) => [
|
||||
<ProfileSheet key="profile" userId={row.id} />,
|
||||
<ProfileSheet
|
||||
key="profile"
|
||||
onUpdated={() => ref.current?.refresh()}
|
||||
userId={row.id}
|
||||
/>,
|
||||
<SubscriptionSheet key="subscription" userId={row.id} />,
|
||||
<ConfirmButton
|
||||
cancelText={t("cancel", "Cancel")}
|
||||
@@ -308,7 +312,13 @@ export default function User() {
|
||||
);
|
||||
}
|
||||
|
||||
function ProfileSheet({ userId }: { userId: number }) {
|
||||
function ProfileSheet({
|
||||
userId,
|
||||
onUpdated,
|
||||
}: {
|
||||
userId: number;
|
||||
onUpdated?: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation("user");
|
||||
const [open, setOpen] = useState(false);
|
||||
const { data: user, refetch } = useQuery({
|
||||
@@ -319,6 +329,12 @@ function ProfileSheet({ userId }: { userId: number }) {
|
||||
return data.data as API.User;
|
||||
},
|
||||
});
|
||||
|
||||
const refetchAll = async () => {
|
||||
await refetch();
|
||||
onUpdated?.();
|
||||
return Promise.resolve();
|
||||
};
|
||||
return (
|
||||
<Sheet onOpenChange={setOpen} open={open}>
|
||||
<SheetTrigger asChild>
|
||||
@@ -348,13 +364,13 @@ function ProfileSheet({ userId }: { userId: number }) {
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
<TabsContent className="mt-0" value="basic">
|
||||
<BasicInfoForm refetch={refetch as any} user={user} />
|
||||
<BasicInfoForm refetch={refetchAll} user={user} />
|
||||
</TabsContent>
|
||||
<TabsContent className="mt-0" value="notify">
|
||||
<NotifySettingsForm refetch={refetch as any} user={user} />
|
||||
<NotifySettingsForm refetch={refetchAll} user={user} />
|
||||
</TabsContent>
|
||||
<TabsContent className="mt-0" value="auth">
|
||||
<AuthMethodsForm refetch={refetch as any} user={user} />
|
||||
<AuthMethodsForm refetch={refetchAll} user={user} />
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</ScrollArea>
|
||||
|
||||
@@ -21,7 +21,7 @@ export function AuthMethodsForm({
|
||||
refetch,
|
||||
}: {
|
||||
user: API.User;
|
||||
refetch: () => void;
|
||||
refetch: () => Promise<unknown>;
|
||||
}) {
|
||||
const { t } = useTranslation("user");
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ export function BasicInfoForm({
|
||||
refetch,
|
||||
}: {
|
||||
user: API.User;
|
||||
refetch: () => void;
|
||||
refetch: () => Promise<unknown>;
|
||||
}) {
|
||||
const { t } = useTranslation("user");
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ export function NotifySettingsForm({
|
||||
refetch,
|
||||
}: {
|
||||
user: API.User;
|
||||
refetch: () => void;
|
||||
refetch: () => Promise<unknown>;
|
||||
}) {
|
||||
const { t } = useTranslation("user");
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { fileURLToPath, URL } from "node:url";
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
import { devtools } from "@tanstack/devtools-vite";
|
||||
@@ -18,6 +18,8 @@ function versionLockPlugin(): Plugin {
|
||||
);
|
||||
const rootPkg = JSON.parse(readFileSync(rootPkgPath, "utf-8"));
|
||||
const version = rootPkg.version || "0.0.0";
|
||||
|
||||
mkdirSync(distDir, { recursive: true });
|
||||
writeFileSync(`${distDir}/version.lock`, version);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>OAuth Redirect</title>
|
||||
<meta http-equiv="refresh" content="0; url=/#/auth">
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
// Providers redirect to a path without URL fragments (#). Our app uses hash routing.
|
||||
// Bridge /oauth/<provider>[/]?... -> /#/oauth/<provider>?...
|
||||
(() => {
|
||||
try {
|
||||
// Normalize trailing slash so /oauth/google/ and /oauth/google both map to the same route.
|
||||
let path = window.location.pathname || "/";
|
||||
path = path.replace(/\/$/, "");
|
||||
|
||||
const search = window.location.search || "";
|
||||
const target = `/#${path}${search}`;
|
||||
window.location.replace(target);
|
||||
} catch (_e) {
|
||||
window.location.replace("/#/auth");
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
</head>
|
||||
<body>Redirecting…</body>
|
||||
</html>
|
||||
@@ -0,0 +1,28 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>OAuth Redirect</title>
|
||||
<meta http-equiv="refresh" content="0; url=/#/auth">
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
// Providers redirect to a path without URL fragments (#). Our app uses hash routing.
|
||||
// Bridge /oauth/<provider>[/]?... -> /#/oauth/<provider>?...
|
||||
(() => {
|
||||
try {
|
||||
let path = window.location.pathname || "/";
|
||||
path = path.replace(/\/$/, "");
|
||||
|
||||
const search = window.location.search || "";
|
||||
const target = `/#${path}${search}`;
|
||||
window.location.replace(target);
|
||||
} catch (_e) {
|
||||
window.location.replace("/#/auth");
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
</head>
|
||||
<body>Redirecting…</body>
|
||||
</html>
|
||||
@@ -35,7 +35,10 @@ export function OAuthMethods() {
|
||||
onClick={async () => {
|
||||
const { data } = await oAuthLogin({
|
||||
method,
|
||||
redirect: `${window.location.origin}/oauth/${method}`,
|
||||
// OAuth providers disallow URL fragments (#) in redirect URIs.
|
||||
// Use a real path (with trailing slash so static hosting can serve /oauth/<provider>/index.html)
|
||||
// which then bridges into our hash-router at /#/oauth/<provider>.
|
||||
redirect: `${window.location.origin}/oauth/${method}/`,
|
||||
});
|
||||
if (data.data?.redirect) {
|
||||
window.location.href = data.data?.redirect;
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
import { cn } from "@workspace/ui/lib/utils";
|
||||
import { getAvailablePaymentMethods } from "@workspace/ui/services/user/portal";
|
||||
import type React from "react";
|
||||
import { memo } from "react";
|
||||
import { memo, useEffect } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
interface PaymentMethodsProps {
|
||||
@@ -30,12 +30,21 @@ const PaymentMethods: React.FC<PaymentMethodsProps> = ({
|
||||
queryFn: async () => {
|
||||
const { data } = await getAvailablePaymentMethods();
|
||||
const list = data.data?.list || [];
|
||||
const methods = balance ? list : list.filter((item) => item.id !== -1);
|
||||
const defaultMethod = methods.find((item) => item.id)?.id;
|
||||
if (defaultMethod) onChange(defaultMethod);
|
||||
return methods;
|
||||
return balance ? list : list.filter((item) => item.id !== -1);
|
||||
},
|
||||
});
|
||||
|
||||
// Only set a default when the current value is not a valid option.
|
||||
// This avoids resetting the user's selection on refetch (common on mobile).
|
||||
// Prefer non-balance methods when possible.
|
||||
useEffect(() => {
|
||||
if (!data || data.length === 0) return;
|
||||
const valid = data.some((m) => String(m.id) === String(value));
|
||||
if (valid) return;
|
||||
|
||||
const preferred = data.find((m) => m.id !== -1)?.id ?? data[0]!.id;
|
||||
onChange(preferred);
|
||||
}, [data, onChange, value]);
|
||||
return (
|
||||
<>
|
||||
<div className="font-semibold">
|
||||
@@ -44,7 +53,6 @@ const PaymentMethods: React.FC<PaymentMethodsProps> = ({
|
||||
<RadioGroup
|
||||
className="grid grid-cols-2 gap-2 md:grid-cols-5"
|
||||
onValueChange={(val) => {
|
||||
console.log(val);
|
||||
onChange(Number(val));
|
||||
}}
|
||||
value={String(value)}
|
||||
|
||||
@@ -11,12 +11,14 @@ import Empty from "@workspace/ui/composed/empty";
|
||||
import { Icon } from "@workspace/ui/composed/icon";
|
||||
import { Markdown } from "@workspace/ui/composed/markdown";
|
||||
import { queryAnnouncement } from "@workspace/ui/services/user/announcement";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useGlobalStore } from "@/stores/global";
|
||||
|
||||
export default function Announcement({ type }: { type: "popup" | "pinned" }) {
|
||||
const { t } = useTranslation("dashboard");
|
||||
const { user } = useGlobalStore();
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const { data } = useQuery({
|
||||
queryKey: ["announcement", type],
|
||||
@@ -37,12 +39,16 @@ export default function Announcement({ type }: { type: "popup" | "pinned" }) {
|
||||
enabled: !!user,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (type === "popup" && !!data) setOpen(true);
|
||||
}, [data, type]);
|
||||
|
||||
if (!data) return null;
|
||||
|
||||
if (type === "popup") {
|
||||
return (
|
||||
<Dialog defaultOpen={!!data}>
|
||||
<DialogContent className="sm:max-w-[425px]">
|
||||
<Dialog onOpenChange={setOpen} open={open}>
|
||||
<DialogContent className="max-h-[85vh] overflow-auto sm:max-w-[425px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{data.title}</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
@@ -276,6 +276,9 @@ const CheckoutForm: React.FC<Omit<StripePaymentProps, "publishable_key">> = ({
|
||||
const stripe = useStripe();
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||
const [qrCodeUrl, setQrCodeUrl] = useState<string | null>(null);
|
||||
const [qrCodeImageDataUrl, setQrCodeImageDataUrl] = useState<string | null>(
|
||||
null
|
||||
);
|
||||
const [isSubmitted, setIsSubmitted] = useState(false);
|
||||
const { t } = useTranslation("payment");
|
||||
const qrCodeMap: Record<string, string> = {
|
||||
@@ -328,12 +331,21 @@ const CheckoutForm: React.FC<Omit<StripePaymentProps, "publishable_key">> = ({
|
||||
|
||||
if (paymentIntent?.status === "requires_action") {
|
||||
const nextAction = paymentIntent.next_action as any;
|
||||
const qrUrl =
|
||||
method === "alipay"
|
||||
? nextAction?.alipay_handle_redirect?.url
|
||||
: nextAction?.wechat_pay_display_qr_code?.image_url_svg;
|
||||
// Stripe returns multiple WeChat QR-related fields.
|
||||
// For native WeChat pay experience we should prefer the protocol data (weixin://...).
|
||||
// Fallback to the provided base64 image if present.
|
||||
if (method === "alipay") {
|
||||
const qrUrl = nextAction?.alipay_handle_redirect?.url;
|
||||
setQrCodeUrl(qrUrl || null);
|
||||
setQrCodeImageDataUrl(null);
|
||||
} else {
|
||||
const wechat = nextAction?.wechat_pay_display_qr_code;
|
||||
const data = wechat?.data; // e.g. weixin://wxpay/bizpayurl?pr=...
|
||||
const imageDataUrl = wechat?.image_data_url; // data:image/png;base64,...
|
||||
|
||||
setQrCodeUrl(qrUrl || null);
|
||||
setQrCodeUrl(data || null);
|
||||
setQrCodeImageDataUrl(data ? null : imageDataUrl || null);
|
||||
}
|
||||
}
|
||||
} catch (_error) {
|
||||
handleError(t("stripe.error", "An error occurred"));
|
||||
@@ -348,18 +360,30 @@ const CheckoutForm: React.FC<Omit<StripePaymentProps, "publishable_key">> = ({
|
||||
<div className="min-w-80 text-left">
|
||||
<CardPaymentForm clientSecret={client_secret} onError={handleError} />
|
||||
</div>
|
||||
) : qrCodeUrl ? (
|
||||
) : qrCodeUrl || qrCodeImageDataUrl ? (
|
||||
<>
|
||||
<QRCodeCanvas
|
||||
imageSettings={{
|
||||
src: `./assets/payment/${method}.svg`,
|
||||
width: 24,
|
||||
height: 24,
|
||||
excavate: true,
|
||||
}}
|
||||
size={208}
|
||||
value={qrCodeUrl}
|
||||
/>
|
||||
{qrCodeImageDataUrl ? (
|
||||
<img
|
||||
alt={
|
||||
qrCodeMap[method] || t(`qrcode.${method}`, `Scan with ${method}`)
|
||||
}
|
||||
className="mx-auto h-[208px] w-[208px]"
|
||||
height={208}
|
||||
src={qrCodeImageDataUrl}
|
||||
width={208}
|
||||
/>
|
||||
) : (
|
||||
<QRCodeCanvas
|
||||
imageSettings={{
|
||||
src: `./assets/payment/${method}.svg`,
|
||||
width: 24,
|
||||
height: 24,
|
||||
excavate: true,
|
||||
}}
|
||||
size={208}
|
||||
value={qrCodeUrl!}
|
||||
/>
|
||||
)}
|
||||
<p className="mt-4 text-center text-muted-foreground">
|
||||
{qrCodeMap[method] || t(`qrcode.${method}`, `Scan with ${method}`)}
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user