import React, { 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'; import tw from 'twin.macro'; import { Button } from '@/components/elements/button/index'; import { Dialog } from '@/components/elements/dialog'; export default () => { const uuid = ServerContext.useStoreState((state) => state.server.data!.uuid); const skipScripts = ServerContext.useStoreState((state) => state.server.data!.skipScripts); const [modalVisible, setModalVisible] = useState(false); const { addFlash, clearFlashes } = useStoreActions((actions: Actions) => actions.flashes); const reinstall = () => { clearFlashes('settings'); reinstallServer(uuid) .then(() => { addFlash({ key: 'settings', type: 'success', message: 'Your server has begun the reinstallation process.', }); }) .catch((error) => { console.error(error); addFlash({ key: 'settings', type: 'error', message: httpErrorToHuman(error) }); }) .then(() => setModalVisible(false)); }; useEffect(() => { clearFlashes(); }, []); if (skipScripts) { return (

Reinstalling this server has been disabled because it is configured to skip its egg's install script. If you would like to reinstall this server, contact a server administrator.

); } return ( setModalVisible(false)} onConfirmed={reinstall} > Your server will be stopped and some files may be deleted or modified during this process, are you sure you wish to continue?

Reinstalling your server will stop it, and then re-run the installation script that initially set it up.  Some files may be deleted or modified during this process, please back up your data before continuing.

setModalVisible(true)}> Reinstall Server
); };