修复(#117): 补齐用户订阅限速配置 UI
This commit is contained in:
@@ -30,13 +30,30 @@ import { Display } from "@/components/display";
|
||||
import { useGlobalStore } from "@/stores/global";
|
||||
import { formatDate } from "@/utils/common";
|
||||
import { SubscriptionDetail } from "./subscription-detail";
|
||||
import { SubscriptionForm } from "./subscription-form";
|
||||
import {
|
||||
SubscriptionForm,
|
||||
type SubscriptionFormValues,
|
||||
} from "./subscription-form";
|
||||
|
||||
interface SharedInfo {
|
||||
ownerUserId: number;
|
||||
familyId: number;
|
||||
}
|
||||
|
||||
function toUserSubscribePayload(values: SubscriptionFormValues) {
|
||||
return {
|
||||
...values,
|
||||
expired_at: values.expired_at || 0,
|
||||
subscribe_id: values.subscribe_id || 0,
|
||||
traffic: values.traffic || 0,
|
||||
upload: values.upload || 0,
|
||||
download: values.download || 0,
|
||||
speed_limit: values.speed_limit || 0,
|
||||
device_limit: values.device_limit || 0,
|
||||
traffic_limit: values.traffic_limit || [],
|
||||
};
|
||||
}
|
||||
|
||||
export default function UserSubscription({ userId }: { userId: number }) {
|
||||
const { t } = useTranslation("user");
|
||||
const [loading, setLoading] = useState(false);
|
||||
@@ -166,7 +183,7 @@ export default function UserSubscription({ userId }: { userId: number }) {
|
||||
await updateUserSubscribe({
|
||||
user_id: Number(userId),
|
||||
user_subscribe_id: row.id,
|
||||
...values,
|
||||
...toUserSubscribePayload(values),
|
||||
});
|
||||
toast.success(t("updateSuccess", "Updated successfully"));
|
||||
ref.current?.refresh();
|
||||
@@ -296,15 +313,39 @@ export default function UserSubscription({ userId }: { userId: number }) {
|
||||
accessorKey: "speed_limit",
|
||||
header: t("speedLimit", "Speed Limit"),
|
||||
cell: ({ row }) => {
|
||||
const speed = row.original?.subscribe?.speed_limit;
|
||||
return <Display type="trafficSpeed" value={speed} />;
|
||||
const userSpeed = row.original.speed_limit ?? 0;
|
||||
const effectiveSpeed = row.original.effective_speed ?? 0;
|
||||
const planSpeed = row.original.subscribe?.speed_limit ?? 0;
|
||||
const speed = effectiveSpeed || userSpeed || planSpeed;
|
||||
const source =
|
||||
userSpeed > 0
|
||||
? t("userOverride", "User Override")
|
||||
: t("subscriptionDefault", "Subscription Default");
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<Display type="trafficSpeed" value={speed} />
|
||||
{row.original.is_throttled && (
|
||||
<Badge variant="destructive">
|
||||
{t("throttled", "Throttled")}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
<span className="text-muted-foreground text-xs">
|
||||
{source}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: "device_limit",
|
||||
header: t("deviceLimit", "Device Limit"),
|
||||
cell: ({ row }) => {
|
||||
const limit = row.original?.subscribe?.device_limit;
|
||||
const limit =
|
||||
row.original.device_limit ||
|
||||
row.original?.subscribe?.device_limit;
|
||||
return <Display type="number" unlimited value={limit} />;
|
||||
},
|
||||
},
|
||||
@@ -352,7 +393,7 @@ export default function UserSubscription({ userId }: { userId: number }) {
|
||||
setLoading(true);
|
||||
await createUserSubscribe({
|
||||
user_id: Number(userId),
|
||||
...values,
|
||||
...toUserSubscribePayload(values),
|
||||
});
|
||||
toast.success(t("createSuccess", "Created successfully"));
|
||||
ref.current?.refresh();
|
||||
|
||||
Reference in New Issue
Block a user