refactored code, fixed checkbox

This commit is contained in:
@jcarymuhammedow
2026-05-22 18:51:45 +05:00
parent 4adc153503
commit d56620be2e
16 changed files with 640 additions and 267 deletions

View File

@@ -0,0 +1,78 @@
import apiClient from '@/lib/api/client'
export type BackupStatus = 'completed' | 'failed' | 'in_progress'
export interface Backup {
id: number
fileName: string
fileSize: string
status: BackupStatus
createdAt: string
createdBy: string
}
export interface BackupListResponse {
data: Backup[]
total: number
page: number
per_page: number
}
export interface BackupListParams {
page?: number
per_page?: number
search?: string
}
const MOCK_BACKUPS: Backup[] = [
{ id: 1, fileName: 'backup_2026_05_22_01.sql', fileSize: '256 MB', status: 'completed', createdAt: '2026-05-22 03:00', createdBy: 'Admin' },
{ id: 2, fileName: 'backup_2026_05_21_01.sql', fileSize: '251 MB', status: 'completed', createdAt: '2026-05-21 03:00', createdBy: 'Admin' },
{ id: 3, fileName: 'backup_2026_05_20_01.sql', fileSize: '248 MB', status: 'completed', createdAt: '2026-05-20 03:00', createdBy: 'Admin' },
{ id: 4, fileName: 'backup_2026_05_19_01.sql', fileSize: '245 MB', status: 'failed', createdAt: '2026-05-19 03:05', createdBy: 'Admin' },
{ id: 5, fileName: 'backup_2026_05_18_01.sql', fileSize: '242 MB', status: 'completed', createdAt: '2026-05-18 03:00', createdBy: 'System' },
]
export const backupsApi = {
getAll: async (params?: BackupListParams): Promise<BackupListResponse> => {
const { data } = await apiClient.get('/backups', { params }).catch(() => ({ data: null }))
if (data) return data
const { search = '', page = 1, per_page = 25 } = params ?? {}
let filtered = [...MOCK_BACKUPS]
if (search) {
const s = search.toLowerCase()
filtered = filtered.filter((b) => b.fileName.toLowerCase().includes(s))
}
const total = filtered.length
const start = (page - 1) * per_page
return { data: filtered.slice(start, start + per_page), total, page, per_page }
},
create: async (): Promise<Backup> => {
const { data } = await apiClient.post('/backups').catch(() => ({ data: null }))
if (data) return data
const newBackup: Backup = {
id: Math.floor(Math.random() * 10000),
fileName: `backup_${new Date().toISOString().slice(0, 10).replace(/-/g, '_')}_01.sql`,
fileSize: '0 MB',
status: 'in_progress',
createdAt: new Date().toLocaleString('tr-TR'),
createdBy: 'Admin',
}
MOCK_BACKUPS.unshift(newBackup)
return newBackup
},
download: async (id: number): Promise<Blob> => {
const { data } = await apiClient.get(`/backups/${id}/download`, { responseType: 'blob' }).catch(() => ({ data: null }))
if (data) return data
return new Blob(['mock backup content'], { type: 'application/sql' })
},
delete: async (id: number): Promise<void> => {
await apiClient.delete(`/backups/${id}`).catch(() => {})
const index = MOCK_BACKUPS.findIndex((b) => b.id === id)
if (index !== -1) MOCK_BACKUPS.splice(index, 1)
},
}

View File

@@ -0,0 +1,58 @@
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { toast } from 'sonner'
import { useTranslation } from 'react-i18next'
import { backupsApi, type BackupListParams } from '../api/backupsApi'
const QUERY_KEY = 'backups'
export function useBackups(params?: BackupListParams) {
return useQuery({
queryKey: [QUERY_KEY, params],
queryFn: () => backupsApi.getAll(params),
})
}
export function useCreateBackup() {
const queryClient = useQueryClient()
const { t } = useTranslation()
return useMutation({
mutationFn: () => backupsApi.create(),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: [QUERY_KEY] })
toast.success(t('backups.toast.created', 'Backup üstünlikli döredildi!'))
},
})
}
export function useDownloadBackup() {
const { t } = useTranslation()
return useMutation({
mutationFn: async (id: number) => {
const blob = await backupsApi.download(id)
const url = URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = url
a.download = `backup-${id}.sql`
a.click()
URL.revokeObjectURL(url)
},
onSuccess: () => {
toast.success(t('backups.toast.downloaded', 'Backup üstünlikli ýüklenildi'))
},
})
}
export function useDeleteBackup() {
const queryClient = useQueryClient()
const { t } = useTranslation()
return useMutation({
mutationFn: (id: number) => backupsApi.delete(id),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: [QUERY_KEY] })
toast.success(t('backups.toast.deleted', 'Backup üstünlikli pozuldy!'))
},
})
}

View File

@@ -121,7 +121,7 @@ export function CurrencyRateForm({ mode, initialData }: CurrencyRateFormProps) {
? t('currencyRates.createTitle', 'Walýuta kursy dörediň')
: t('currencyRates.editTitle', 'Walýuta kursy üýtgetmek')}
</h1>
<div className="space-y-6">
<div className="space-y-6 bg-card border border-border rounded-xl overflow-hidden">
{/* Currency From */}
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
<label className="text-sm text-muted-foreground pt-1.5">

View File

@@ -139,7 +139,7 @@ export function VisaMasterSettingForm({
? t('visaMasterSettings.createTitle', 'Visa/Master, Sber sazlamalar dörediň')
: t('visaMasterSettings.editTitle', 'Visa/Master, Sber sazlamalar üýtgetmek')}
</h1>
<div className="space-y-0">
<div className="space-y-0 bg-card border border-border rounded-xl overflow-hidden">
{/* Kod */}
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
<label className="text-sm text-muted-foreground pt-1.5">