653 lines
25 KiB
TypeScript
653 lines
25 KiB
TypeScript
/**
|
|
* Admin UI for Android APK release lifecycle: create, upload, publish, suspend, stats.
|
|
*/
|
|
import {
|
|
Alert,
|
|
Box,
|
|
Button,
|
|
Chip,
|
|
Dialog,
|
|
DialogActions,
|
|
DialogContent,
|
|
DialogTitle,
|
|
FormControl,
|
|
InputLabel,
|
|
LinearProgress,
|
|
MenuItem,
|
|
Select,
|
|
Stack,
|
|
Tab,
|
|
Table,
|
|
TableBody,
|
|
TableCell,
|
|
TableHead,
|
|
TableRow,
|
|
Tabs,
|
|
TextField,
|
|
Typography,
|
|
} from '@mui/material';
|
|
import PhoneAndroidRoundedIcon from '@mui/icons-material/PhoneAndroidRounded';
|
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
import { useMemo, useRef, useState } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { PermissionGate } from '../../shared/auth/PermissionGate';
|
|
import { useAuth } from '../../shared/auth/AuthContext';
|
|
import { ScrollableTable } from '../../shared/components/ScrollableTable';
|
|
import {
|
|
createMobileRelease,
|
|
deleteMobileRelease,
|
|
getMobileReleaseStats,
|
|
getMobileUpdateSettings,
|
|
listMobileReleases,
|
|
publishMobileRelease,
|
|
retireMobileRelease,
|
|
submitMobileRelease,
|
|
suspendMobileRelease,
|
|
updateMobileRelease,
|
|
updateMobileUpdateSettings,
|
|
uploadMobileApk,
|
|
type MobileAppRelease,
|
|
type MobileUpdatePolicy,
|
|
type UploadProgress,
|
|
} from './api/mobileVersionsApi';
|
|
|
|
function formatBytes(n: number | null): string {
|
|
if (n == null) return '—';
|
|
if (n < 1024) return `${n} B`;
|
|
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`;
|
|
return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
}
|
|
|
|
function formatEta(seconds: number | null, t: (k: string, o?: Record<string, unknown>) => string): string {
|
|
if (seconds == null) return t('admin.mobileVersions.etaCalculating');
|
|
if (seconds < 5) return t('admin.mobileVersions.etaAlmostDone');
|
|
if (seconds < 60) return t('admin.mobileVersions.etaSeconds', { count: seconds });
|
|
const m = Math.floor(seconds / 60);
|
|
const s = seconds % 60;
|
|
return t('admin.mobileVersions.etaMinutes', { minutes: m, seconds: s });
|
|
}
|
|
|
|
function statusColor(status: string): 'default' | 'success' | 'warning' | 'error' | 'info' {
|
|
switch (status) {
|
|
case 'published':
|
|
return 'success';
|
|
case 'pending_validation':
|
|
return 'info';
|
|
case 'suspended':
|
|
return 'warning';
|
|
case 'retired':
|
|
return 'error';
|
|
default:
|
|
return 'default';
|
|
}
|
|
}
|
|
|
|
type CreateForm = {
|
|
versionName: string;
|
|
versionCode: string;
|
|
previousVersionName: string;
|
|
whatsNew: string;
|
|
bugFixes: string;
|
|
updatePolicy: MobileUpdatePolicy;
|
|
rolloutPercent: string;
|
|
};
|
|
|
|
const emptyCreate: CreateForm = {
|
|
versionName: '',
|
|
versionCode: '',
|
|
previousVersionName: '',
|
|
whatsNew: '',
|
|
bugFixes: '',
|
|
updatePolicy: 'optional',
|
|
rolloutPercent: '100',
|
|
};
|
|
|
|
function errMsg(e: unknown, fallback: string): string {
|
|
const ax = e as {
|
|
response?: { status?: number; data?: { error?: string; message?: string } };
|
|
message?: string;
|
|
code?: string;
|
|
};
|
|
if (ax.response?.status === 413) {
|
|
return 'APK too large for the server (nginx/body limit).';
|
|
}
|
|
return ax.response?.data?.error || ax.response?.data?.message || ax.message || fallback;
|
|
}
|
|
|
|
export function MobileVersionsAdminPage() {
|
|
const { t } = useTranslation();
|
|
const { can } = useAuth();
|
|
const canManage = can('admin.mobile_releases.manage');
|
|
const qc = useQueryClient();
|
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
|
|
const [tab, setTab] = useState(0);
|
|
const [statusFilter, setStatusFilter] = useState('');
|
|
const [search, setSearch] = useState('');
|
|
const [createOpen, setCreateOpen] = useState(false);
|
|
const [form, setForm] = useState<CreateForm>(emptyCreate);
|
|
const [selected, setSelected] = useState<MobileAppRelease | null>(null);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [uploadProgress, setUploadProgress] = useState<UploadProgress | null>(null);
|
|
const [uploadPhase, setUploadPhase] = useState<'idle' | 'uploading' | 'processing'>('idle');
|
|
const [settingsForm, setSettingsForm] = useState({
|
|
minSupportedVersionCode: '1',
|
|
checkIntervalSeconds: '21600',
|
|
expectedPackageName: 'com.prediqo.mobile',
|
|
});
|
|
|
|
const listQ = useQuery({
|
|
queryKey: ['admin-mobile-releases', statusFilter, search],
|
|
queryFn: () =>
|
|
listMobileReleases({
|
|
status: statusFilter || undefined,
|
|
search: search || undefined,
|
|
limit: 100,
|
|
}),
|
|
});
|
|
|
|
const statsQ = useQuery({
|
|
queryKey: ['admin-mobile-release-stats'],
|
|
queryFn: getMobileReleaseStats,
|
|
enabled: tab === 1,
|
|
});
|
|
|
|
const settingsQ = useQuery({
|
|
queryKey: ['admin-mobile-update-settings'],
|
|
queryFn: async () => {
|
|
const s = await getMobileUpdateSettings();
|
|
setSettingsForm({
|
|
minSupportedVersionCode: String(s.minSupportedVersionCode),
|
|
checkIntervalSeconds: String(s.checkIntervalSeconds),
|
|
expectedPackageName: s.expectedPackageName,
|
|
});
|
|
return s;
|
|
},
|
|
enabled: tab === 2,
|
|
});
|
|
|
|
const invalidate = () => {
|
|
void qc.invalidateQueries({ queryKey: ['admin-mobile-releases'] });
|
|
void qc.invalidateQueries({ queryKey: ['admin-mobile-release-stats'] });
|
|
};
|
|
|
|
const createMut = useMutation({
|
|
mutationFn: createMobileRelease,
|
|
onSuccess: (rel) => {
|
|
setCreateOpen(false);
|
|
setForm(emptyCreate);
|
|
setSelected(rel);
|
|
setError(null);
|
|
invalidate();
|
|
},
|
|
onError: (e: unknown) => setError(errMsg(e, t('admin.mobileVersions.actionFailed'))),
|
|
});
|
|
|
|
const actionMut = useMutation({
|
|
mutationFn: async (args: {
|
|
action: string;
|
|
id: string;
|
|
file?: File;
|
|
patch?: Parameters<typeof updateMobileRelease>[1];
|
|
}) => {
|
|
const { action, id, file, patch } = args;
|
|
if (action === 'upload' && file) {
|
|
setUploadPhase('uploading');
|
|
setUploadProgress({ percent: 0, loaded: 0, total: file.size, etaSeconds: null });
|
|
try {
|
|
const result = await uploadMobileApk(id, file, (p) => {
|
|
setUploadProgress(p);
|
|
if (p.percent >= 100) setUploadPhase('processing');
|
|
});
|
|
return result;
|
|
} finally {
|
|
/* phase cleared in onSettled */
|
|
}
|
|
}
|
|
if (action === 'submit') return submitMobileRelease(id);
|
|
if (action === 'publish') return publishMobileRelease(id);
|
|
if (action === 'suspend') return suspendMobileRelease(id);
|
|
if (action === 'retire') return retireMobileRelease(id);
|
|
if (action === 'delete') return deleteMobileRelease(id);
|
|
if (action === 'patch' && patch) return updateMobileRelease(id, patch);
|
|
throw new Error('Unknown action');
|
|
},
|
|
onSuccess: (rel) => {
|
|
if (rel && typeof rel === 'object' && 'deleted' in rel && rel.deleted) {
|
|
setSelected(null);
|
|
} else if (rel && typeof rel === 'object' && 'id' in rel) {
|
|
setSelected(rel as MobileAppRelease);
|
|
}
|
|
setError(null);
|
|
invalidate();
|
|
},
|
|
onError: (e: unknown) => setError(errMsg(e, t('admin.mobileVersions.actionFailed'))),
|
|
onSettled: () => {
|
|
setUploadPhase('idle');
|
|
setUploadProgress(null);
|
|
},
|
|
});
|
|
|
|
const settingsMut = useMutation({
|
|
mutationFn: updateMobileUpdateSettings,
|
|
onSuccess: () => {
|
|
void qc.invalidateQueries({ queryKey: ['admin-mobile-update-settings'] });
|
|
setError(null);
|
|
},
|
|
onError: (e: unknown) => setError(errMsg(e, t('admin.mobileVersions.actionFailed'))),
|
|
});
|
|
|
|
const rows = listQ.data?.items ?? [];
|
|
const detail = selected;
|
|
|
|
const policyLabel = useMemo(
|
|
() => ({
|
|
optional: t('admin.mobileVersions.policyOptional'),
|
|
recommended: t('admin.mobileVersions.policyRecommended'),
|
|
mandatory: t('admin.mobileVersions.policyMandatory'),
|
|
}),
|
|
[t]
|
|
);
|
|
|
|
return (
|
|
<Box sx={{ minWidth: 0 }}>
|
|
<Stack direction="row" spacing={1.5} sx={{ alignItems: 'center', mb: 2 }}>
|
|
<PhoneAndroidRoundedIcon color="primary" />
|
|
<Box sx={{ flex: 1 }}>
|
|
<Typography variant="h4" sx={{ fontWeight: 900 }}>
|
|
{t('admin.mobileVersions.title')}
|
|
</Typography>
|
|
<Typography variant="body2" color="text.secondary">
|
|
{t('admin.mobileVersions.subtitle')}
|
|
</Typography>
|
|
</Box>
|
|
<PermissionGate permission="admin.mobile_releases.manage">
|
|
<Button variant="contained" onClick={() => setCreateOpen(true)}>
|
|
{t('admin.mobileVersions.newRelease')}
|
|
</Button>
|
|
</PermissionGate>
|
|
</Stack>
|
|
|
|
{error && (
|
|
<Alert severity="error" sx={{ mb: 2 }} onClose={() => setError(null)}>
|
|
{error}
|
|
</Alert>
|
|
)}
|
|
|
|
<Tabs value={tab} onChange={(_, v) => setTab(v)} sx={{ mb: 2 }}>
|
|
<Tab label={t('admin.mobileVersions.tabReleases')} />
|
|
<Tab label={t('admin.mobileVersions.tabStats')} />
|
|
<Tab label={t('admin.mobileVersions.tabSettings')} />
|
|
</Tabs>
|
|
|
|
{tab === 0 && (
|
|
<Stack spacing={2}>
|
|
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={1.5}>
|
|
<TextField
|
|
size="small"
|
|
label={t('admin.mobileVersions.search')}
|
|
value={search}
|
|
onChange={(e) => setSearch(e.target.value)}
|
|
sx={{ minWidth: 220 }}
|
|
/>
|
|
<FormControl size="small" sx={{ minWidth: 180 }}>
|
|
<InputLabel>{t('admin.mobileVersions.status')}</InputLabel>
|
|
<Select
|
|
label={t('admin.mobileVersions.status')}
|
|
value={statusFilter}
|
|
onChange={(e) => setStatusFilter(e.target.value)}
|
|
>
|
|
<MenuItem value="">{t('admin.mobileVersions.allStatuses')}</MenuItem>
|
|
<MenuItem value="draft">draft</MenuItem>
|
|
<MenuItem value="pending_validation">pending_validation</MenuItem>
|
|
<MenuItem value="published">published</MenuItem>
|
|
<MenuItem value="suspended">suspended</MenuItem>
|
|
<MenuItem value="retired">retired</MenuItem>
|
|
</Select>
|
|
</FormControl>
|
|
</Stack>
|
|
|
|
<ScrollableTable minWidth={720}>
|
|
<Table size="small">
|
|
<TableHead>
|
|
<TableRow>
|
|
<TableCell>{t('admin.mobileVersions.version')}</TableCell>
|
|
<TableCell>{t('admin.mobileVersions.versionCode')}</TableCell>
|
|
<TableCell>{t('admin.mobileVersions.status')}</TableCell>
|
|
<TableCell>{t('admin.mobileVersions.policy')}</TableCell>
|
|
<TableCell>{t('admin.mobileVersions.size')}</TableCell>
|
|
<TableCell>{t('admin.mobileVersions.downloads')}</TableCell>
|
|
<TableCell>{t('admin.mobileVersions.publishedAt')}</TableCell>
|
|
</TableRow>
|
|
</TableHead>
|
|
<TableBody>
|
|
{rows.map((r) => (
|
|
<TableRow
|
|
key={r.id}
|
|
hover
|
|
selected={selected?.id === r.id}
|
|
onClick={() => setSelected(r)}
|
|
sx={{ cursor: 'pointer' }}
|
|
>
|
|
<TableCell>{r.versionName}</TableCell>
|
|
<TableCell>{r.versionCode}</TableCell>
|
|
<TableCell>
|
|
<Chip size="small" label={r.status} color={statusColor(r.status)} />
|
|
</TableCell>
|
|
<TableCell>{policyLabel[r.updatePolicy]}</TableCell>
|
|
<TableCell>{formatBytes(r.fileSizeBytes)}</TableCell>
|
|
<TableCell>{r.downloadCount}</TableCell>
|
|
<TableCell>{r.publishedAt ? new Date(r.publishedAt).toLocaleString() : '—'}</TableCell>
|
|
</TableRow>
|
|
))}
|
|
{!listQ.isLoading && rows.length === 0 && (
|
|
<TableRow>
|
|
<TableCell colSpan={7} align="center">
|
|
{t('admin.mobileVersions.empty')}
|
|
</TableCell>
|
|
</TableRow>
|
|
)}
|
|
</TableBody>
|
|
</Table>
|
|
</ScrollableTable>
|
|
|
|
{detail && (
|
|
<Box
|
|
sx={{
|
|
p: 2,
|
|
borderRadius: 2,
|
|
border: '1px solid',
|
|
borderColor: 'divider',
|
|
bgcolor: 'background.paper',
|
|
}}
|
|
>
|
|
<Stack direction="row" justifyContent="space-between" alignItems="center" sx={{ mb: 1 }}>
|
|
<Typography variant="h6" sx={{ fontWeight: 800 }}>
|
|
{detail.versionName} (#{detail.versionCode})
|
|
</Typography>
|
|
<Chip size="small" label={detail.status} color={statusColor(detail.status)} />
|
|
</Stack>
|
|
<Typography variant="body2" color="text.secondary" sx={{ mb: 1 }}>
|
|
{t('admin.mobileVersions.package')}: {detail.packageName || '—'} · SHA-256:{' '}
|
|
{detail.sha256 ? `${detail.sha256.slice(0, 16)}…` : '—'} · rollout {detail.rolloutPercent}%
|
|
</Typography>
|
|
<Typography variant="body2" sx={{ whiteSpace: 'pre-wrap', mb: 1 }}>
|
|
<strong>{t('admin.mobileVersions.whatsNew')}</strong>
|
|
{'\n'}
|
|
{detail.whatsNew || '—'}
|
|
</Typography>
|
|
<Typography variant="body2" sx={{ whiteSpace: 'pre-wrap', mb: 2 }}>
|
|
<strong>{t('admin.mobileVersions.bugFixes')}</strong>
|
|
{'\n'}
|
|
{detail.bugFixes || '—'}
|
|
</Typography>
|
|
|
|
<PermissionGate permission="admin.mobile_releases.manage">
|
|
{uploadPhase !== 'idle' && uploadProgress && (
|
|
<Box sx={{ mb: 2, p: 1.5, borderRadius: 2, border: '1px solid', borderColor: 'divider' }}>
|
|
<Stack direction="row" justifyContent="space-between" sx={{ mb: 0.75 }}>
|
|
<Typography variant="body2" sx={{ fontWeight: 700 }}>
|
|
{uploadPhase === 'processing'
|
|
? t('admin.mobileVersions.uploadProcessing')
|
|
: t('admin.mobileVersions.uploading')}
|
|
</Typography>
|
|
<Typography variant="body2" color="text.secondary">
|
|
{uploadProgress.percent}% · {formatBytes(uploadProgress.loaded)} /{' '}
|
|
{formatBytes(uploadProgress.total)}
|
|
</Typography>
|
|
</Stack>
|
|
<LinearProgress
|
|
variant={uploadPhase === 'processing' ? 'indeterminate' : 'determinate'}
|
|
value={uploadProgress.percent}
|
|
sx={{ height: 8, borderRadius: 999 }}
|
|
/>
|
|
<Typography variant="caption" color="text.secondary" sx={{ mt: 0.75, display: 'block' }}>
|
|
{uploadPhase === 'processing'
|
|
? t('admin.mobileVersions.uploadProcessingHint')
|
|
: formatEta(uploadProgress.etaSeconds, t)}
|
|
</Typography>
|
|
</Box>
|
|
)}
|
|
<Stack direction="row" flexWrap="wrap" gap={1}>
|
|
<input
|
|
ref={fileInputRef}
|
|
type="file"
|
|
accept=".apk,application/vnd.android.package-archive"
|
|
hidden
|
|
onChange={(e) => {
|
|
const file = e.target.files?.[0];
|
|
if (file) {
|
|
setError(null);
|
|
actionMut.mutate({ action: 'upload', id: detail.id, file });
|
|
}
|
|
e.target.value = '';
|
|
}}
|
|
/>
|
|
<Button
|
|
variant="outlined"
|
|
disabled={!canManage || actionMut.isPending}
|
|
onClick={() => fileInputRef.current?.click()}
|
|
>
|
|
{actionMut.isPending && uploadPhase !== 'idle'
|
|
? t('admin.mobileVersions.uploading')
|
|
: t('admin.mobileVersions.uploadApk')}
|
|
</Button>
|
|
<Button
|
|
variant="outlined"
|
|
disabled={actionMut.isPending || !detail.storageKey}
|
|
onClick={() => actionMut.mutate({ action: 'submit', id: detail.id })}
|
|
>
|
|
{t('admin.mobileVersions.submit')}
|
|
</Button>
|
|
<Button
|
|
variant="contained"
|
|
disabled={actionMut.isPending || !detail.storageKey}
|
|
onClick={() => actionMut.mutate({ action: 'publish', id: detail.id })}
|
|
>
|
|
{t('admin.mobileVersions.publish')}
|
|
</Button>
|
|
<Button
|
|
color="warning"
|
|
disabled={actionMut.isPending || detail.status !== 'published'}
|
|
onClick={() => actionMut.mutate({ action: 'suspend', id: detail.id })}
|
|
>
|
|
{t('admin.mobileVersions.suspend')}
|
|
</Button>
|
|
<Button
|
|
color="error"
|
|
disabled={actionMut.isPending || detail.status === 'retired'}
|
|
onClick={() => actionMut.mutate({ action: 'retire', id: detail.id })}
|
|
>
|
|
{t('admin.mobileVersions.retire')}
|
|
</Button>
|
|
<Button
|
|
color="error"
|
|
variant="outlined"
|
|
disabled={actionMut.isPending}
|
|
onClick={() => {
|
|
const ok = window.confirm(
|
|
t('admin.mobileVersions.deleteConfirm', {
|
|
version: detail.versionName,
|
|
code: detail.versionCode,
|
|
})
|
|
);
|
|
if (ok) actionMut.mutate({ action: 'delete', id: detail.id });
|
|
}}
|
|
>
|
|
{t('admin.mobileVersions.delete')}
|
|
</Button>
|
|
</Stack>
|
|
</PermissionGate>
|
|
</Box>
|
|
)}
|
|
</Stack>
|
|
)}
|
|
|
|
{tab === 1 && (
|
|
<Stack spacing={2}>
|
|
{statsQ.isLoading && <Typography>{t('admin.mobileVersions.loading')}</Typography>}
|
|
{statsQ.data && (
|
|
<>
|
|
<Stack direction="row" flexWrap="wrap" gap={1}>
|
|
{statsQ.data.byStatus.map((s) => (
|
|
<Chip key={s.status} label={`${s.status}: ${s.count}`} />
|
|
))}
|
|
</Stack>
|
|
<Stack direction="row" flexWrap="wrap" gap={1}>
|
|
{statsQ.data.eventCounts.map((e) => (
|
|
<Chip key={e.eventType} color="info" variant="outlined" label={`${e.eventType}: ${e.count}`} />
|
|
))}
|
|
</Stack>
|
|
<ScrollableTable minWidth={640}>
|
|
<Table size="small">
|
|
<TableHead>
|
|
<TableRow>
|
|
<TableCell>{t('admin.mobileVersions.version')}</TableCell>
|
|
<TableCell>{t('admin.mobileVersions.versionCode')}</TableCell>
|
|
<TableCell>{t('admin.mobileVersions.status')}</TableCell>
|
|
<TableCell>{t('admin.mobileVersions.downloads')}</TableCell>
|
|
<TableCell>{t('admin.mobileVersions.downloadFails')}</TableCell>
|
|
<TableCell>{t('admin.mobileVersions.installs')}</TableCell>
|
|
</TableRow>
|
|
</TableHead>
|
|
<TableBody>
|
|
{statsQ.data.byVersion.map((r) => (
|
|
<TableRow key={r.id}>
|
|
<TableCell>{r.versionName}</TableCell>
|
|
<TableCell>{r.versionCode}</TableCell>
|
|
<TableCell>{r.status}</TableCell>
|
|
<TableCell>{r.downloadCount}</TableCell>
|
|
<TableCell>{r.downloadFailCount}</TableCell>
|
|
<TableCell>{r.installConfirmCount}</TableCell>
|
|
</TableRow>
|
|
))}
|
|
</TableBody>
|
|
</Table>
|
|
</ScrollableTable>
|
|
</>
|
|
)}
|
|
</Stack>
|
|
)}
|
|
|
|
{tab === 2 && (
|
|
<Stack spacing={2} sx={{ maxWidth: 480 }}>
|
|
{settingsQ.isLoading && <Typography>{t('admin.mobileVersions.loading')}</Typography>}
|
|
<TextField
|
|
label={t('admin.mobileVersions.minSupported')}
|
|
value={settingsForm.minSupportedVersionCode}
|
|
onChange={(e) => setSettingsForm((s) => ({ ...s, minSupportedVersionCode: e.target.value }))}
|
|
disabled={!canManage}
|
|
/>
|
|
<TextField
|
|
label={t('admin.mobileVersions.checkInterval')}
|
|
value={settingsForm.checkIntervalSeconds}
|
|
onChange={(e) => setSettingsForm((s) => ({ ...s, checkIntervalSeconds: e.target.value }))}
|
|
disabled={!canManage}
|
|
helperText={t('admin.mobileVersions.checkIntervalHint')}
|
|
/>
|
|
<TextField
|
|
label={t('admin.mobileVersions.expectedPackage')}
|
|
value={settingsForm.expectedPackageName}
|
|
onChange={(e) => setSettingsForm((s) => ({ ...s, expectedPackageName: e.target.value }))}
|
|
disabled={!canManage}
|
|
/>
|
|
<PermissionGate permission="admin.mobile_releases.manage">
|
|
<Button
|
|
variant="contained"
|
|
disabled={settingsMut.isPending}
|
|
onClick={() =>
|
|
settingsMut.mutate({
|
|
minSupportedVersionCode: Number(settingsForm.minSupportedVersionCode),
|
|
checkIntervalSeconds: Number(settingsForm.checkIntervalSeconds),
|
|
expectedPackageName: settingsForm.expectedPackageName,
|
|
})
|
|
}
|
|
>
|
|
{t('admin.mobileVersions.saveSettings')}
|
|
</Button>
|
|
</PermissionGate>
|
|
</Stack>
|
|
)}
|
|
|
|
<Dialog open={createOpen} onClose={() => setCreateOpen(false)} fullWidth maxWidth="sm">
|
|
<DialogTitle>{t('admin.mobileVersions.newRelease')}</DialogTitle>
|
|
<DialogContent>
|
|
<Stack spacing={2} sx={{ mt: 1 }}>
|
|
<TextField
|
|
label={t('admin.mobileVersions.version')}
|
|
value={form.versionName}
|
|
onChange={(e) => setForm((f) => ({ ...f, versionName: e.target.value }))}
|
|
required
|
|
/>
|
|
<TextField
|
|
label={t('admin.mobileVersions.versionCode')}
|
|
value={form.versionCode}
|
|
onChange={(e) => setForm((f) => ({ ...f, versionCode: e.target.value }))}
|
|
required
|
|
type="number"
|
|
/>
|
|
<TextField
|
|
label={t('admin.mobileVersions.previousVersion')}
|
|
value={form.previousVersionName}
|
|
onChange={(e) => setForm((f) => ({ ...f, previousVersionName: e.target.value }))}
|
|
/>
|
|
<FormControl>
|
|
<InputLabel>{t('admin.mobileVersions.policy')}</InputLabel>
|
|
<Select
|
|
label={t('admin.mobileVersions.policy')}
|
|
value={form.updatePolicy}
|
|
onChange={(e) => setForm((f) => ({ ...f, updatePolicy: e.target.value as MobileUpdatePolicy }))}
|
|
>
|
|
<MenuItem value="optional">{policyLabel.optional}</MenuItem>
|
|
<MenuItem value="recommended">{policyLabel.recommended}</MenuItem>
|
|
<MenuItem value="mandatory">{policyLabel.mandatory}</MenuItem>
|
|
</Select>
|
|
</FormControl>
|
|
<TextField
|
|
label={t('admin.mobileVersions.rollout')}
|
|
value={form.rolloutPercent}
|
|
onChange={(e) => setForm((f) => ({ ...f, rolloutPercent: e.target.value }))}
|
|
type="number"
|
|
helperText={t('admin.mobileVersions.rolloutHint')}
|
|
/>
|
|
<TextField
|
|
label={t('admin.mobileVersions.whatsNew')}
|
|
value={form.whatsNew}
|
|
onChange={(e) => setForm((f) => ({ ...f, whatsNew: e.target.value }))}
|
|
multiline
|
|
minRows={3}
|
|
/>
|
|
<TextField
|
|
label={t('admin.mobileVersions.bugFixes')}
|
|
value={form.bugFixes}
|
|
onChange={(e) => setForm((f) => ({ ...f, bugFixes: e.target.value }))}
|
|
multiline
|
|
minRows={2}
|
|
/>
|
|
</Stack>
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<Button onClick={() => setCreateOpen(false)}>{t('admin.mobileVersions.cancel')}</Button>
|
|
<Button
|
|
variant="contained"
|
|
disabled={createMut.isPending || !form.versionName || !form.versionCode}
|
|
onClick={() =>
|
|
createMut.mutate({
|
|
versionName: form.versionName.trim(),
|
|
versionCode: Number(form.versionCode),
|
|
previousVersionName: form.previousVersionName.trim() || null,
|
|
whatsNew: form.whatsNew,
|
|
bugFixes: form.bugFixes,
|
|
updatePolicy: form.updatePolicy,
|
|
rolloutPercent: Number(form.rolloutPercent) || 100,
|
|
})
|
|
}
|
|
>
|
|
{t('admin.mobileVersions.create')}
|
|
</Button>
|
|
</DialogActions>
|
|
</Dialog>
|
|
</Box>
|
|
);
|
|
}
|