fix: complete Douyin release remediation
This commit is contained in:
+142
-14
@@ -1,4 +1,4 @@
|
||||
import { useMemo, useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Link, useParams } from "react-router";
|
||||
import { useDataProvider, useList, useOne } from "@refinedev/core";
|
||||
import {
|
||||
@@ -59,8 +59,8 @@ function ExitHealthPill({ exit }) {
|
||||
);
|
||||
}
|
||||
|
||||
function ExitActions({ exit, busy, onAction }) {
|
||||
const disabled = busy || exit.health_status === "disabled";
|
||||
function ExitActions({ exit, busy, onAction, onEdit, onDelete }) {
|
||||
const disabled = busy;
|
||||
return (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button
|
||||
@@ -71,21 +71,65 @@ function ExitActions({ exit, busy, onAction }) {
|
||||
>
|
||||
检测
|
||||
</Button>
|
||||
{exit.health_status === "disabled" ? (
|
||||
<Button
|
||||
size="sm"
|
||||
icon="ri-checkbox-circle-line"
|
||||
disabled={disabled}
|
||||
onClick={() => onAction(exit, "enable")}
|
||||
>
|
||||
启用
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="danger"
|
||||
icon="ri-forbid-line"
|
||||
disabled={disabled}
|
||||
onClick={() => onAction(exit, "disable")}
|
||||
>
|
||||
停用
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
size="sm"
|
||||
variant="danger"
|
||||
icon="ri-forbid-line"
|
||||
variant="outline"
|
||||
disabled={disabled}
|
||||
onClick={() => onAction(exit, "disable")}
|
||||
onClick={() => onEdit(exit)}
|
||||
>
|
||||
停用
|
||||
编辑
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
disabled={disabled}
|
||||
onClick={() => onDelete(exit)}
|
||||
>
|
||||
删除
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ExitCreateModal({ open, onClose, onSubmit, busy, error }) {
|
||||
const [form, setForm] = useState(createInitial);
|
||||
function ExitCreateModal({
|
||||
open,
|
||||
onClose,
|
||||
onSubmit,
|
||||
busy,
|
||||
error,
|
||||
initialValue = createInitial,
|
||||
title = "创建网络出口",
|
||||
submitLabel = "创建网络出口",
|
||||
}) {
|
||||
const [form, setForm] = useState({ ...createInitial, ...initialValue });
|
||||
useEffect(() => {
|
||||
if (open)
|
||||
setForm({
|
||||
...createInitial,
|
||||
...initialValue,
|
||||
port: initialValue.port ? String(initialValue.port) : "",
|
||||
});
|
||||
}, [open, initialValue]);
|
||||
const update = (key, value) =>
|
||||
setForm((current) => ({ ...current, [key]: value }));
|
||||
const port = Number(form.port);
|
||||
@@ -119,7 +163,7 @@ function ExitCreateModal({ open, onClose, onSubmit, busy, error }) {
|
||||
<Modal
|
||||
open={open}
|
||||
onClose={onClose}
|
||||
title="创建网络出口"
|
||||
title={title}
|
||||
labelledBy="exit-create-title"
|
||||
size="lg"
|
||||
footer={
|
||||
@@ -135,7 +179,7 @@ function ExitCreateModal({ open, onClose, onSubmit, busy, error }) {
|
||||
busyText="创建中…"
|
||||
disabled={!valid}
|
||||
>
|
||||
创建网络出口
|
||||
{submitLabel}
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
@@ -240,7 +284,15 @@ function ExitCreateModal({ open, onClose, onSubmit, busy, error }) {
|
||||
);
|
||||
}
|
||||
|
||||
function ExitTable({ exits, accountsByExit, bindingsError, busy, onAction }) {
|
||||
function ExitTable({
|
||||
exits,
|
||||
accountsByExit,
|
||||
bindingsError,
|
||||
busy,
|
||||
onAction,
|
||||
onEdit,
|
||||
onDelete,
|
||||
}) {
|
||||
const columns = [
|
||||
{
|
||||
header: "出口",
|
||||
@@ -313,7 +365,13 @@ function ExitTable({ exits, accountsByExit, bindingsError, busy, onAction }) {
|
||||
width: "8%",
|
||||
align: "right",
|
||||
render: (exit) => (
|
||||
<ExitActions exit={exit} busy={busy === exit.id} onAction={onAction} />
|
||||
<ExitActions
|
||||
exit={exit}
|
||||
busy={busy === exit.id}
|
||||
onAction={onAction}
|
||||
onEdit={onEdit}
|
||||
onDelete={onDelete}
|
||||
/>
|
||||
),
|
||||
},
|
||||
];
|
||||
@@ -334,6 +392,8 @@ export function NetworkExitList() {
|
||||
const [createError, setCreateError] = useState(null);
|
||||
const [notice, setNotice] = useState(null);
|
||||
const [disabling, setDisabling] = useState(null);
|
||||
const [editing, setEditing] = useState(null);
|
||||
const [deleting, setDeleting] = useState(null);
|
||||
const { result, query } = useList({ resource: "network-exits" });
|
||||
const error = query.error;
|
||||
const isPending = query.isPending;
|
||||
@@ -377,6 +437,51 @@ export function NetworkExitList() {
|
||||
}
|
||||
}
|
||||
|
||||
async function updateExit(exit, data) {
|
||||
setBusy(`edit:${exit.id}`);
|
||||
setNotice(null);
|
||||
try {
|
||||
await dataProvider.update({
|
||||
resource: "network-exits",
|
||||
id: exit.id,
|
||||
variables: data,
|
||||
});
|
||||
await query.refetch();
|
||||
setEditing(null);
|
||||
setNotice({
|
||||
variant: "success",
|
||||
text: "网络出口已更新,需重新检测后才能使用。",
|
||||
});
|
||||
return true;
|
||||
} catch (reason) {
|
||||
setNotice({
|
||||
variant: "destructive",
|
||||
text: conflictMessage(reason, "出口当前不能修改。"),
|
||||
});
|
||||
return false;
|
||||
} finally {
|
||||
setBusy("");
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteExit(exit) {
|
||||
setBusy(`delete:${exit.id}`);
|
||||
setNotice(null);
|
||||
try {
|
||||
await dataProvider.delete({ resource: "network-exits", id: exit.id });
|
||||
await query.refetch();
|
||||
setDeleting(null);
|
||||
setNotice({ variant: "success", text: "网络出口已删除。" });
|
||||
} catch (reason) {
|
||||
setNotice({
|
||||
variant: "destructive",
|
||||
text: conflictMessage(reason, "出口仍有绑定或运行实例,不能删除。"),
|
||||
});
|
||||
} finally {
|
||||
setBusy("");
|
||||
}
|
||||
}
|
||||
|
||||
async function runAction(exit, action) {
|
||||
setBusy(exit.id);
|
||||
setNotice(null);
|
||||
@@ -388,7 +493,9 @@ export function NetworkExitList() {
|
||||
text:
|
||||
action === "check"
|
||||
? "出口检测完成。"
|
||||
: "出口已停用;绑定账号不会自动恢复。",
|
||||
: action === "enable"
|
||||
? "出口已启用;重新检测通过后才能绑定。"
|
||||
: "出口已停用;绑定账号不会自动恢复。",
|
||||
});
|
||||
} catch (reason) {
|
||||
setNotice({
|
||||
@@ -451,6 +558,8 @@ export function NetworkExitList() {
|
||||
onAction={(exit, action) =>
|
||||
action === "disable" ? setDisabling(exit) : runAction(exit, action)
|
||||
}
|
||||
onEdit={(exit) => setEditing(exit)}
|
||||
onDelete={(exit) => setDeleting(exit)}
|
||||
/>
|
||||
</PageState>
|
||||
<ExitCreateModal
|
||||
@@ -463,6 +572,25 @@ export function NetworkExitList() {
|
||||
busy={busy === "create"}
|
||||
error={createError}
|
||||
/>
|
||||
<ExitCreateModal
|
||||
open={editing !== null}
|
||||
onClose={() => setEditing(null)}
|
||||
onSubmit={(data) => updateExit(editing, data)}
|
||||
busy={busy === `edit:${editing?.id}`}
|
||||
error={null}
|
||||
initialValue={editing || createInitial}
|
||||
title="编辑网络出口"
|
||||
submitLabel="保存网络出口"
|
||||
/>
|
||||
<ConfirmDialog
|
||||
open={deleting !== null}
|
||||
onClose={() => setDeleting(null)}
|
||||
onConfirm={() => deleteExit(deleting)}
|
||||
title="删除网络出口"
|
||||
confirmLabel="确认删除"
|
||||
busy={busy === `delete:${deleting?.id}`}
|
||||
body={`删除网络出口 ${deleting?.id}?有绑定或运行实例时会拒绝。`}
|
||||
/>
|
||||
<ConfirmDialog
|
||||
open={disabling !== null}
|
||||
onClose={() => setDisabling(null)}
|
||||
|
||||
Reference in New Issue
Block a user