2020-08-04 03:58:15 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2020-04-03 21:43:24 +00:00
|
|
|
import { ServerContext } from '@/state/server';
|
|
|
|
import TitledGreyBox from '@/components/elements/TitledGreyBox';
|
|
|
|
import ConfirmationModal from '@/components/elements/ConfirmationModal';
|
|
|
|
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';
|
2020-04-03 21:43:24 +00:00
|
|
|
|
|
|
|
export default () => {
|
|
|
|
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
|
|
|
|
const [ isSubmitting, setIsSubmitting ] = useState(false);
|
|
|
|
const [ modalVisible, setModalVisible ] = useState(false);
|
|
|
|
const { addFlash, clearFlashes } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
|
|
|
|
|
|
|
|
const reinstall = () => {
|
|
|
|
clearFlashes('settings');
|
|
|
|
setIsSubmitting(true);
|
|
|
|
reinstallServer(uuid)
|
|
|
|
.then(() => {
|
2020-07-04 22:58:14 +00:00
|
|
|
addFlash({
|
|
|
|
key: 'settings',
|
|
|
|
type: 'success',
|
|
|
|
message: 'Your server has begun the reinstallation process.',
|
|
|
|
});
|
2020-04-03 21:43:24 +00:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error(error);
|
|
|
|
|
|
|
|
addFlash({ key: 'settings', type: 'error', message: httpErrorToHuman(error) });
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
setIsSubmitting(false);
|
|
|
|
setModalVisible(false);
|
|
|
|
});
|
2020-07-04 22:58:14 +00:00
|
|
|
};
|
2020-04-03 21:43:24 +00:00
|
|
|
|
2020-08-04 03:58:15 +00:00
|
|
|
useEffect(() => {
|
|
|
|
clearFlashes();
|
|
|
|
}, []);
|
|
|
|
|
2020-04-03 21:43:24 +00:00
|
|
|
return (
|
2020-07-04 22:58:14 +00:00
|
|
|
<TitledGreyBox title={'Reinstall Server'} css={tw`relative`}>
|
2020-04-03 21:43:24 +00:00
|
|
|
<ConfirmationModal
|
|
|
|
title={'Confirm server reinstallation'}
|
|
|
|
buttonText={'Yes, reinstall server'}
|
|
|
|
onConfirmed={() => reinstall()}
|
|
|
|
showSpinnerOverlay={isSubmitting}
|
|
|
|
visible={modalVisible}
|
|
|
|
onDismissed={() => setModalVisible(false)}
|
|
|
|
>
|
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?
|
2020-04-03 21:43:24 +00:00
|
|
|
</ConfirmationModal>
|
2020-07-04 22:58:14 +00:00
|
|
|
<p css={tw`text-sm`}>
|
2020-04-03 21:43:24 +00:00
|
|
|
Reinstalling your server will stop it, and then re-run the installation script that initially
|
2020-07-04 22:58:14 +00:00
|
|
|
set it up.
|
|
|
|
<strong css={tw`font-medium`}>
|
|
|
|
Some files may be deleted or modified during this process, please back up your data before
|
|
|
|
continuing.
|
|
|
|
</strong>
|
2020-04-03 21:43:24 +00:00
|
|
|
</p>
|
2020-07-04 22:58:14 +00:00
|
|
|
<div css={tw`mt-6 text-right`}>
|
|
|
|
<Button
|
2020-04-03 21:43:24 +00:00
|
|
|
type={'button'}
|
2020-07-04 22:58:14 +00:00
|
|
|
color={'red'}
|
|
|
|
isSecondary
|
2020-04-03 21:43:24 +00:00
|
|
|
onClick={() => setModalVisible(true)}
|
|
|
|
>
|
|
|
|
Reinstall Server
|
2020-07-04 22:58:14 +00:00
|
|
|
</Button>
|
2020-04-03 21:43:24 +00:00
|
|
|
</div>
|
|
|
|
</TitledGreyBox>
|
|
|
|
);
|
|
|
|
};
|