fix(admin): remove manual reasons and repair code creation
This commit is contained in:
@@ -18,7 +18,7 @@ import {
|
||||
import { useState } from "react";
|
||||
|
||||
import { adminRequestJson, type AdminIdentity } from "@/lib/admin/providers";
|
||||
import { ReasonActionModal } from "./reason-action-modal";
|
||||
import { ConfirmActionModal } from "./confirm-action-modal";
|
||||
import { formatAdminDate, ResourceTable } from "./resource-table";
|
||||
|
||||
const { Text } = Typography;
|
||||
@@ -58,7 +58,6 @@ export function SubscriptionsResource() {
|
||||
item: Subscription,
|
||||
action: "extend" | "revoke",
|
||||
days: number | undefined,
|
||||
reason: string,
|
||||
) {
|
||||
await adminRequestJson("/api/admin/subscriptions", {
|
||||
method: "POST",
|
||||
@@ -67,7 +66,6 @@ export function SubscriptionsResource() {
|
||||
action,
|
||||
days,
|
||||
expectedEndsAt: item.endsAt,
|
||||
reason,
|
||||
}),
|
||||
});
|
||||
await table.tableQuery.refetch();
|
||||
@@ -77,11 +75,11 @@ export function SubscriptionsResource() {
|
||||
setExtendDays(values.days);
|
||||
}
|
||||
|
||||
async function extend(reason: string) {
|
||||
async function extend() {
|
||||
if (!selected || extendDays === null) return;
|
||||
setSaving(true);
|
||||
try {
|
||||
await adjust(selected, "extend", extendDays, reason);
|
||||
await adjust(selected, "extend", extendDays);
|
||||
message.success("订阅已延长");
|
||||
setExtendDays(null);
|
||||
setSelected(null);
|
||||
@@ -91,10 +89,10 @@ export function SubscriptionsResource() {
|
||||
}
|
||||
}
|
||||
|
||||
async function revoke(item: Subscription, reason: string) {
|
||||
async function revoke(item: Subscription) {
|
||||
setRevokingId(item.id);
|
||||
try {
|
||||
await adjust(item, "revoke", undefined, reason);
|
||||
await adjust(item, "revoke", undefined);
|
||||
message.success("订阅已撤销");
|
||||
setRevokeTarget(null);
|
||||
} finally {
|
||||
@@ -182,7 +180,7 @@ export function SubscriptionsResource() {
|
||||
<Modal
|
||||
title="人工延长订阅"
|
||||
open={Boolean(selected && extendDays === null)}
|
||||
okText="继续验证"
|
||||
okText="继续"
|
||||
cancelText="取消"
|
||||
onOk={() => form.submit()}
|
||||
onCancel={() => setSelected(null)}
|
||||
@@ -203,22 +201,22 @@ export function SubscriptionsResource() {
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
<ReasonActionModal
|
||||
<ConfirmActionModal
|
||||
open={Boolean(selected && extendDays !== null)}
|
||||
title="延长订阅权益"
|
||||
okText="确认延长"
|
||||
confirmLoading={saving}
|
||||
onCancel={() => setExtendDays(null)}
|
||||
onSubmit={extend}
|
||||
onConfirm={extend}
|
||||
/>
|
||||
<ReasonActionModal
|
||||
<ConfirmActionModal
|
||||
open={Boolean(revokeTarget)}
|
||||
title="撤销订阅权益"
|
||||
okText="确认撤销"
|
||||
danger
|
||||
confirmLoading={Boolean(revokingId)}
|
||||
onCancel={() => setRevokeTarget(null)}
|
||||
onSubmit={(reason) => revoke(revokeTarget!, reason)}
|
||||
onConfirm={() => revoke(revokeTarget!)}
|
||||
/>
|
||||
</List>
|
||||
);
|
||||
@@ -258,7 +256,7 @@ export function OrdersResource() {
|
||||
identity?.permissions.includes("billing.adjustments.write"),
|
||||
);
|
||||
|
||||
async function adjust(reason: string) {
|
||||
async function adjust() {
|
||||
if (!target) return;
|
||||
setSaving(true);
|
||||
try {
|
||||
@@ -271,7 +269,6 @@ export function OrdersResource() {
|
||||
id: target.order.id,
|
||||
action: target.action,
|
||||
expectedVersion: target.order.adjustmentVersion,
|
||||
reason,
|
||||
}),
|
||||
});
|
||||
await invalidate({ resource: "orders", invalidates: ["list"] });
|
||||
@@ -422,14 +419,14 @@ export function OrdersResource() {
|
||||
"recorded",
|
||||
].map((value) => ({ value, label: value }))}
|
||||
/>
|
||||
<ReasonActionModal
|
||||
<ConfirmActionModal
|
||||
open={Boolean(target)}
|
||||
title={modalTitle}
|
||||
okText="确认执行"
|
||||
danger={target?.action === "record_refund"}
|
||||
confirmLoading={saving}
|
||||
onCancel={() => setTarget(null)}
|
||||
onSubmit={adjust}
|
||||
onConfirm={adjust}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user