mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 17:43:47 +00:00
refactor(devices): close all MED/LOW review items
- Extract DEVICE_ALIAS_MAX_LENGTH to src/constants/devices.ts so the
user page and admin page share one source of truth (mirroring the
bot's ALIAS_MAX_LENGTH=64). Was duplicated as a magic 64 in both
files (MED-5).
- Replace ✓ / ✕ / ✏️ glyphs in AdminUserDetail.tsx with inline SVGs,
matching the icon style already used by Subscription.tsx for the
same rename/save/cancel actions. Eliminates the platform-dependent
emoji rendering inconsistency (MED-4).
- Add haptic feedback to the user-side renameDeviceMutation —
notification('success') on save, notification('error') on failure.
Brings it in line with the other Subscription.tsx mutations
(LOW-9).
- Translate the new rename keys into zh.json and fa.json (en.json
already covered in the previous follow-up). Cabinet now ships full
parity across all 4 locales for the rename UI.
This commit is contained in:
@@ -3,6 +3,7 @@ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Navigate, useNavigate, useParams } from 'react-router';
|
||||
import { subscriptionApi } from '../api/subscription';
|
||||
import { DEVICE_ALIAS_MAX_LENGTH } from '../constants/devices';
|
||||
import { WebBackButton } from '../components/WebBackButton';
|
||||
import { useDestructiveConfirm } from '../platform/hooks/useNativeDialog';
|
||||
import { usePlatform } from '../platform';
|
||||
@@ -313,19 +314,23 @@ export default function Subscription() {
|
||||
// identifier of the row being edited.
|
||||
const [editingDeviceHwid, setEditingDeviceHwid] = useState<string | null>(null);
|
||||
const [editingDeviceName, setEditingDeviceName] = useState('');
|
||||
const DEVICE_ALIAS_MAX_LENGTH = 64;
|
||||
|
||||
const renameDeviceMutation = useMutation({
|
||||
mutationFn: ({ hwid, name }: { hwid: string; name: string | null }) =>
|
||||
subscriptionApi.renameDevice(hwid, name, subscriptionId),
|
||||
onSuccess: (_data, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['devices', subscriptionId] });
|
||||
// Soft success-tap, like other mutations on this page.
|
||||
haptic.notification('success');
|
||||
// Не сбрасываем edit-state, если пользователь уже перешёл на другой
|
||||
// девайс пока шёл запрос — иначе теряем его новый input. Имя не чистим
|
||||
// безусловно: оно либо принадлежит уже другому девайсу (нужно сохранить),
|
||||
// либо инпут уже закрылся (значение не отображается).
|
||||
setEditingDeviceHwid((current) => (current === variables.hwid ? null : current));
|
||||
},
|
||||
onError: () => {
|
||||
haptic.notification('error');
|
||||
},
|
||||
});
|
||||
|
||||
// Pause subscription mutation
|
||||
|
||||
Reference in New Issue
Block a user