2020-04-03 14:43:24 -07:00
|
|
|
import TitledGreyBox from '@/components/elements/TitledGreyBox';
|
2026-10-05 18:10:18 -04:00
|
|
|
import Button from '@/components/elements/Button';
|
2022-06-20 11:17:33 -04:00
|
|
|
import { Dialog } from '@/components/elements/dialog';
|
2026-10-05 18:10:18 -04:00
|
|
|
import { useCurrentServer, useReinstallServer } from '@/api/server/queries';
|
|
|
|
|
import { canReinstallServer, SKIPPED_INSTALL_SCRIPT_MESSAGE } from '@/lib/serverStatus';
|
2020-04-03 14:43:24 -07:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
const ReinstallServerBox = () => {
|
|
|
|
|
const server = useCurrentServer()!;
|
|
|
|
|
const reinstallServer = useReinstallServer();
|
|
|
|
|
const canReinstall = canReinstallServer(server.attributes.status, server.attributes.skip_scripts);
|
2020-04-03 14:43:24 -07:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
const reinstall = async (close: () => void) => {
|
|
|
|
|
try {
|
|
|
|
|
await reinstallServer.mutateAsync({ path: { server_uuid: server.attributes.uuid } });
|
|
|
|
|
close();
|
|
|
|
|
} catch {
|
|
|
|
|
// Error toast is handled by the mutation.
|
|
|
|
|
}
|
2020-07-04 15:58:14 -07:00
|
|
|
};
|
2020-04-03 14:43:24 -07:00
|
|
|
|
|
|
|
|
return (
|
2026-10-05 18:10:18 -04:00
|
|
|
<TitledGreyBox title={'Reinstall Server'} className={'relative'}>
|
|
|
|
|
<p className={'text-sm'}>
|
2022-06-26 15:13:52 -04:00
|
|
|
Reinstalling your server will stop it, and then re-run the installation script that initially set it
|
|
|
|
|
up.
|
2026-10-05 18:10:18 -04:00
|
|
|
<strong className={'font-medium'}>
|
2020-07-04 15:58:14 -07:00
|
|
|
Some files may be deleted or modified during this process, please back up your data before
|
|
|
|
|
continuing.
|
|
|
|
|
</strong>
|
2020-04-03 14:43:24 -07:00
|
|
|
</p>
|
2026-10-05 18:10:18 -04:00
|
|
|
{!canReinstall && <p className={'mt-3 text-sm text-muted-foreground'}>{SKIPPED_INSTALL_SCRIPT_MESSAGE}</p>}
|
|
|
|
|
<Dialog.ConfirmTrigger
|
|
|
|
|
title={'Confirm server reinstallation'}
|
|
|
|
|
confirm={'Yes, reinstall server'}
|
|
|
|
|
onConfirmed={(_event, close) => reinstall(close)}
|
|
|
|
|
trigger={({ onClick }) => (
|
|
|
|
|
<div className={'mt-6 text-right'}>
|
|
|
|
|
<Button.Danger isSecondary disabled={!canReinstall} onClick={onClick}>
|
|
|
|
|
Reinstall Server
|
|
|
|
|
</Button.Danger>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
Your server will be stopped and some files may be deleted or modified during this process, are you sure
|
|
|
|
|
you wish to continue?
|
|
|
|
|
</Dialog.ConfirmTrigger>
|
2020-04-03 14:43:24 -07:00
|
|
|
</TitledGreyBox>
|
|
|
|
|
);
|
|
|
|
|
};
|
2026-10-05 18:10:18 -04:00
|
|
|
|
|
|
|
|
export default ReinstallServerBox;
|