2020-04-04 17:59:25 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2020-07-27 03:32:24 +00:00
|
|
|
import { Helmet } from 'react-helmet';
|
2020-04-04 17:59:25 +00:00
|
|
|
import Spinner from '@/components/elements/Spinner';
|
2020-04-10 19:41:08 +00:00
|
|
|
import getServerBackups from '@/api/server/backups/getServerBackups';
|
2020-04-04 17:59:25 +00:00
|
|
|
import useServer from '@/plugins/useServer';
|
|
|
|
import useFlash from '@/plugins/useFlash';
|
|
|
|
import { httpErrorToHuman } from '@/api/http';
|
|
|
|
import Can from '@/components/elements/Can';
|
|
|
|
import CreateBackupButton from '@/components/server/backups/CreateBackupButton';
|
|
|
|
import FlashMessageRender from '@/components/FlashMessageRender';
|
2020-04-04 20:24:03 +00:00
|
|
|
import BackupRow from '@/components/server/backups/BackupRow';
|
2020-04-07 05:25:54 +00:00
|
|
|
import { ServerContext } from '@/state/server';
|
2020-04-17 18:17:01 +00:00
|
|
|
import PageContentBlock from '@/components/elements/PageContentBlock';
|
2020-07-04 23:26:07 +00:00
|
|
|
import tw from 'twin.macro';
|
2020-04-04 17:59:25 +00:00
|
|
|
|
|
|
|
export default () => {
|
2020-08-02 03:49:00 +00:00
|
|
|
const { uuid, featureLimits, name: serverName } = useServer();
|
2020-04-04 17:59:25 +00:00
|
|
|
const { addError, clearFlashes } = useFlash();
|
|
|
|
const [ loading, setLoading ] = useState(true);
|
2020-04-07 05:25:54 +00:00
|
|
|
|
|
|
|
const backups = ServerContext.useStoreState(state => state.backups.data);
|
|
|
|
const setBackups = ServerContext.useStoreActions(actions => actions.backups.setBackups);
|
2020-04-04 17:59:25 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
clearFlashes('backups');
|
|
|
|
getServerBackups(uuid)
|
2020-04-07 05:25:54 +00:00
|
|
|
.then(data => setBackups(data.items))
|
2020-04-04 17:59:25 +00:00
|
|
|
.catch(error => {
|
|
|
|
console.error(error);
|
|
|
|
addError({ key: 'backups', message: httpErrorToHuman(error) });
|
|
|
|
})
|
|
|
|
.then(() => setLoading(false));
|
|
|
|
}, []);
|
|
|
|
|
2020-04-07 05:25:54 +00:00
|
|
|
if (backups.length === 0 && loading) {
|
2020-07-04 23:26:07 +00:00
|
|
|
return <Spinner size={'large'} centered/>;
|
2020-04-04 17:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2020-04-17 18:17:01 +00:00
|
|
|
<PageContentBlock>
|
2020-07-27 03:32:24 +00:00
|
|
|
<Helmet>
|
2020-08-02 03:49:00 +00:00
|
|
|
<title> {serverName} | Backups</title>
|
2020-07-27 03:32:24 +00:00
|
|
|
</Helmet>
|
2020-07-04 23:26:07 +00:00
|
|
|
<FlashMessageRender byKey={'backups'} css={tw`mb-4`}/>
|
2020-04-04 17:59:25 +00:00
|
|
|
{!backups.length ?
|
2020-07-04 23:26:07 +00:00
|
|
|
<p css={tw`text-center text-sm text-neutral-400`}>
|
2020-04-04 17:59:25 +00:00
|
|
|
There are no backups stored for this server.
|
|
|
|
</p>
|
|
|
|
:
|
|
|
|
<div>
|
2020-04-04 20:24:03 +00:00
|
|
|
{backups.map((backup, index) => <BackupRow
|
|
|
|
key={backup.uuid}
|
|
|
|
backup={backup}
|
2020-07-04 23:26:07 +00:00
|
|
|
css={index > 0 ? tw`mt-2` : undefined}
|
2020-04-04 20:24:03 +00:00
|
|
|
/>)}
|
2020-04-04 17:59:25 +00:00
|
|
|
</div>
|
|
|
|
}
|
2020-06-03 03:14:16 +00:00
|
|
|
{featureLimits.backups === 0 &&
|
2020-07-22 05:54:49 +00:00
|
|
|
<p css={tw`text-center text-sm text-neutral-400`}>
|
2020-06-03 03:14:16 +00:00
|
|
|
Backups cannot be created for this server.
|
|
|
|
</p>
|
|
|
|
}
|
2020-04-04 17:59:25 +00:00
|
|
|
<Can action={'backup.create'}>
|
2020-06-24 03:13:58 +00:00
|
|
|
{(featureLimits.backups > 0 && backups.length > 0) &&
|
2020-07-04 23:26:07 +00:00
|
|
|
<p css={tw`text-center text-xs text-neutral-400 mt-2`}>
|
2020-06-24 03:13:58 +00:00
|
|
|
{backups.length} of {featureLimits.backups} backups have been created for this server.
|
|
|
|
</p>
|
|
|
|
}
|
2020-06-03 03:14:16 +00:00
|
|
|
{featureLimits.backups > 0 && featureLimits.backups !== backups.length &&
|
2020-07-04 23:26:07 +00:00
|
|
|
<div css={tw`mt-6 flex justify-end`}>
|
2020-04-07 05:25:54 +00:00
|
|
|
<CreateBackupButton/>
|
2020-04-04 17:59:25 +00:00
|
|
|
</div>
|
2020-06-03 03:14:16 +00:00
|
|
|
}
|
2020-04-04 17:59:25 +00:00
|
|
|
</Can>
|
2020-04-17 18:17:01 +00:00
|
|
|
</PageContentBlock>
|
2020-04-04 17:59:25 +00:00
|
|
|
);
|
|
|
|
};
|