2020-08-21 04:44:33 +00:00
|
|
|
import React, { useEffect } 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';
|
|
|
|
import useServer from '@/plugins/useServer';
|
|
|
|
import useFlash from '@/plugins/useFlash';
|
|
|
|
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-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-08-21 04:44:33 +00:00
|
|
|
import getServerBackups from '@/api/swr/getServerBackups';
|
2020-04-04 17:59:25 +00:00
|
|
|
|
|
|
|
export default () => {
|
2020-08-21 04:44:33 +00:00
|
|
|
const { clearFlashes, clearAndAddHttpError } = useFlash();
|
|
|
|
const { featureLimits, name: serverName } = useServer();
|
2020-04-07 05:25:54 +00:00
|
|
|
|
2020-08-21 04:44:33 +00:00
|
|
|
const { data: backups, error, isValidating } = getServerBackups();
|
2020-04-04 17:59:25 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2020-08-21 04:44:33 +00:00
|
|
|
if (!error) {
|
|
|
|
clearFlashes('backups');
|
2020-04-04 17:59:25 +00:00
|
|
|
|
2020-08-21 04:44:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
clearAndAddHttpError({ error, key: 'backups' });
|
|
|
|
}, [ error ]);
|
|
|
|
|
|
|
|
if (!backups || (error && isValidating)) {
|
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-21 04:44:33 +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-08-21 04:44:33 +00:00
|
|
|
{!backups.items.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-08-21 04:44:33 +00:00
|
|
|
{backups.items.map((backup, index) => <BackupRow
|
2020-04-04 20:24:03 +00:00
|
|
|
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-08-21 04:44:33 +00:00
|
|
|
<p css={tw`text-center text-sm text-neutral-400`}>
|
|
|
|
Backups cannot be created for this server.
|
|
|
|
</p>
|
2020-06-03 03:14:16 +00:00
|
|
|
}
|
2020-04-04 17:59:25 +00:00
|
|
|
<Can action={'backup.create'}>
|
2020-08-21 04:44:33 +00:00
|
|
|
{(featureLimits.backups > 0 && backups.items.length > 0) &&
|
2020-07-04 23:26:07 +00:00
|
|
|
<p css={tw`text-center text-xs text-neutral-400 mt-2`}>
|
2020-08-21 04:44:33 +00:00
|
|
|
{backups.items.length} of {featureLimits.backups} backups have been created for this server.
|
2020-06-24 03:13:58 +00:00
|
|
|
</p>
|
|
|
|
}
|
2020-08-21 04:44:33 +00:00
|
|
|
{featureLimits.backups > 0 && featureLimits.backups !== backups.items.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
|
|
|
);
|
|
|
|
};
|