74 lines
2.3 KiB
TypeScript
74 lines
2.3 KiB
TypeScript
import { useState } from 'react'
|
||
import { FcAcceptDatabase } from 'react-icons/fc'
|
||
import { Button } from '@/components/ui'
|
||
import ConfirmDialog from '@/components/shared/ConfirmDialog'
|
||
import { UiEvalService } from '@/services/UiEvalService'
|
||
import { useLocalization } from '@/utils/hooks/useLocalization'
|
||
import { usePermission } from '@/utils/hooks/usePermission'
|
||
import { DB_MIGRATE } from '@/constants/permission.constant'
|
||
|
||
interface DbMigrateButtonProps {
|
||
/** Küçük ekranlarda etiketi gizle (yalnızca ikon göster). */
|
||
hideLabelOnMobile?: boolean
|
||
className?: string
|
||
/** Migrate hatasız bittiğinde çağrılır. */
|
||
onCompleted?: () => void
|
||
}
|
||
|
||
/**
|
||
* "DB Migrate" aksiyonu — onay diyaloğu ve yetki kontrolü dahil.
|
||
*
|
||
* SQL Query Manager ve Wizard dosya yöneticisi aynı işi yaptığı için tek bileşende
|
||
* toplanmıştır. Yetkisi olmayan kullanıcıya buton hiç render edilmez; asıl kontrol
|
||
* yine de sunucuda (`App.Setup.Migrate`) yapılır.
|
||
*/
|
||
const DbMigrateButton = ({
|
||
hideLabelOnMobile = false,
|
||
className,
|
||
onCompleted,
|
||
}: DbMigrateButtonProps) => {
|
||
const { translate } = useLocalization()
|
||
const { checkPermission } = usePermission()
|
||
const [isConfirmOpen, setIsConfirmOpen] = useState(false)
|
||
|
||
if (!checkPermission(DB_MIGRATE)) {
|
||
return null
|
||
}
|
||
|
||
const label = translate('::App.ListForm.DbMigrate')
|
||
|
||
return (
|
||
<>
|
||
<Button
|
||
size="sm"
|
||
variant="default"
|
||
icon={<FcAcceptDatabase />}
|
||
className={className}
|
||
onClick={() => setIsConfirmOpen(true)}
|
||
title={translate('::App.Platform.StartMessage')}
|
||
>
|
||
{hideLabelOnMobile ? <span className="hidden sm:inline">{label}</span> : label}
|
||
</Button>
|
||
|
||
<ConfirmDialog
|
||
isOpen={isConfirmOpen}
|
||
type="info"
|
||
title={label}
|
||
cancelText={translate('::App.Platform.Cancel')}
|
||
confirmText={translate('::App.Platform.Execute')}
|
||
onCancel={() => setIsConfirmOpen(false)}
|
||
onClose={() => setIsConfirmOpen(false)}
|
||
onConfirm={() => {
|
||
setIsConfirmOpen(false)
|
||
UiEvalService.ApiDbMigrate(onCompleted, true)
|
||
}}
|
||
>
|
||
<p className="text-gray-600 dark:text-gray-400">
|
||
{translate('::App.DbMigrate.ConfirmMessage')}
|
||
</p>
|
||
</ConfirmDialog>
|
||
</>
|
||
)
|
||
}
|
||
|
||
export default DbMigrateButton
|