fix: show user subscription speed override
This commit is contained in:
@@ -54,6 +54,10 @@ function toUserSubscribePayload(values: SubscriptionFormValues) {
|
||||
};
|
||||
}
|
||||
|
||||
function resolvePlanSpeed(row: API.UserSubscribe) {
|
||||
return row.plan_speed_limit ?? row.subscribe?.speed_limit ?? 0;
|
||||
}
|
||||
|
||||
export default function UserSubscription({ userId }: { userId: number }) {
|
||||
const { t } = useTranslation("user");
|
||||
const [loading, setLoading] = useState(false);
|
||||
@@ -315,10 +319,11 @@ export default function UserSubscription({ userId }: { userId: number }) {
|
||||
cell: ({ row }) => {
|
||||
const userSpeed = row.original.speed_limit ?? 0;
|
||||
const effectiveSpeed = row.original.effective_speed ?? 0;
|
||||
const planSpeed = row.original.subscribe?.speed_limit ?? 0;
|
||||
const planSpeed = resolvePlanSpeed(row.original);
|
||||
const speed = effectiveSpeed || userSpeed || planSpeed;
|
||||
const source =
|
||||
userSpeed > 0
|
||||
const source = row.original.is_throttled
|
||||
? t("effectiveSpeed", "Effective Speed")
|
||||
: userSpeed > 0
|
||||
? t("userOverride", "User Override")
|
||||
: t("subscriptionDefault", "Subscription Default");
|
||||
|
||||
@@ -335,6 +340,16 @@ export default function UserSubscription({ userId }: { userId: number }) {
|
||||
<span className="text-muted-foreground text-xs">
|
||||
{source}
|
||||
</span>
|
||||
<span className="text-muted-foreground text-xs">
|
||||
{t("userOverride", "User Override")}:{" "}
|
||||
<span className="inline-block">
|
||||
<Display type="trafficSpeed" value={userSpeed} />
|
||||
</span>{" "}
|
||||
/ {t("subscriptionDefault", "Subscription Default")}:{" "}
|
||||
<span className="inline-block">
|
||||
<Display type="trafficSpeed" value={planSpeed} />
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
|
||||
@@ -87,11 +87,12 @@ function SpeedLimitCard({ subscriptionId }: { subscriptionId: number }) {
|
||||
|
||||
if (detail.status !== 1) return null;
|
||||
|
||||
const baseSpeed = detail.subscribe?.speed_limit ?? 0;
|
||||
const baseSpeed =
|
||||
detail.plan_speed_limit ?? detail.subscribe?.speed_limit ?? 0;
|
||||
const userSpeed = detail.speed_limit ?? 0;
|
||||
const effectiveSpeed = detail.effective_speed ?? 0;
|
||||
const isThrottled = detail.is_throttled;
|
||||
const rules = detail.traffic_limit || [];
|
||||
const rules = detail.user_traffic_limit || detail.traffic_limit || [];
|
||||
const hasLimitConfig =
|
||||
baseSpeed > 0 || userSpeed > 0 || effectiveSpeed > 0 || rules.length > 0;
|
||||
|
||||
|
||||
@@ -40,6 +40,12 @@ interface Props {
|
||||
|
||||
type SubscriptionTrafficLimitRule = API.UserSubscribeTrafficLimitRule;
|
||||
|
||||
function getUserTrafficLimitRules(
|
||||
data?: Pick<API.UserSubscribe, "traffic_limit" | "user_traffic_limit">
|
||||
) {
|
||||
return data?.user_traffic_limit || data?.traffic_limit || [];
|
||||
}
|
||||
|
||||
const defaultLimitRule: SubscriptionTrafficLimitRule = {
|
||||
stat_type: "day",
|
||||
stat_value: 1,
|
||||
@@ -98,7 +104,7 @@ export function SubscriptionForm({
|
||||
traffic: initialData?.traffic || 0,
|
||||
speed_limit: initialData?.speed_limit || 0,
|
||||
device_limit: initialData?.device_limit || 0,
|
||||
traffic_limit: initialData?.traffic_limit || [],
|
||||
traffic_limit: getUserTrafficLimitRules(initialData),
|
||||
upload: initialData?.upload || 0,
|
||||
download: initialData?.download || 0,
|
||||
expired_at: initialData?.expire_time || 0,
|
||||
|
||||
+4
@@ -2664,11 +2664,13 @@ declare namespace API {
|
||||
download: number;
|
||||
upload: number;
|
||||
speed_limit?: number;
|
||||
plan_speed_limit?: number;
|
||||
device_limit?: number;
|
||||
effective_speed?: number;
|
||||
is_throttled?: boolean;
|
||||
throttle_rule?: string;
|
||||
traffic_limit?: UserSubscribeTrafficLimitRule[];
|
||||
user_traffic_limit?: UserSubscribeTrafficLimitRule[];
|
||||
token: string;
|
||||
status: number;
|
||||
short: string;
|
||||
@@ -2699,8 +2701,10 @@ declare namespace API {
|
||||
download: number;
|
||||
upload: number;
|
||||
speed_limit?: number;
|
||||
plan_speed_limit?: number;
|
||||
device_limit?: number;
|
||||
traffic_limit?: UserSubscribeTrafficLimitRule[];
|
||||
user_traffic_limit?: UserSubscribeTrafficLimitRule[];
|
||||
token: string;
|
||||
status: number;
|
||||
effective_speed: number;
|
||||
|
||||
Reference in New Issue
Block a user