misc_pterodactyl-panel/resources/scripts/components/server/settings/ReinstallServerBox.tsx

67 lines
2.6 KiB
TypeScript
Raw Normal View History

2022-11-25 20:25:03 +00:00
import { useEffect, useState } from 'react';
import { ServerContext } from '@/state/server';
import TitledGreyBox from '@/components/elements/TitledGreyBox';
import reinstallServer from '@/api/server/reinstallServer';
import { Actions, useStoreActions } from 'easy-peasy';
import { ApplicationStore } from '@/state';
import { httpErrorToHuman } from '@/api/http';
2020-07-04 22:58:14 +00:00
import tw from 'twin.macro';
import { Button } from '@/components/elements/button/index';
import { Dialog } from '@/components/elements/dialog';
export default () => {
2022-11-25 20:25:03 +00:00
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
const [modalVisible, setModalVisible] = useState(false);
const { addFlash, clearFlashes } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
const reinstall = () => {
clearFlashes('settings');
reinstallServer(uuid)
.then(() => {
2020-07-04 22:58:14 +00:00
addFlash({
key: 'settings',
type: 'success',
message: 'Your server has begun the reinstallation process.',
});
})
2022-11-25 20:25:03 +00:00
.catch(error => {
console.error(error);
addFlash({ key: 'settings', type: 'error', message: httpErrorToHuman(error) });
})
.then(() => setModalVisible(false));
2020-07-04 22:58:14 +00:00
};
useEffect(() => {
clearFlashes();
}, []);
return (
2020-07-04 22:58:14 +00:00
<TitledGreyBox title={'Reinstall Server'} css={tw`relative`}>
<Dialog.Confirm
open={modalVisible}
title={'Confirm server reinstallation'}
confirm={'Yes, reinstall server'}
onClose={() => setModalVisible(false)}
onConfirmed={reinstall}
>
2020-07-04 22:58:14 +00:00
Your server will be stopped and some files may be deleted or modified during this process, are you sure
you wish to continue?
</Dialog.Confirm>
2020-07-04 22:58:14 +00:00
<p css={tw`text-sm`}>
Reinstalling your server will stop it, and then re-run the installation script that initially set it
up.&nbsp;
2020-07-04 22:58:14 +00:00
<strong css={tw`font-medium`}>
Some files may be deleted or modified during this process, please back up your data before
continuing.
</strong>
</p>
2020-07-04 22:58:14 +00:00
<div css={tw`mt-6 text-right`}>
<Button.Danger variant={Button.Variants.Secondary} onClick={() => setModalVisible(true)}>
Reinstall Server
</Button.Danger>
</div>
</TitledGreyBox>
);
};