2020-08-21 04:44:33 +00:00
|
|
|
import React, { useEffect } from 'react';
|
2020-04-04 17:59:25 +00:00
|
|
|
import Spinner from '@/components/elements/Spinner';
|
|
|
|
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-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-08-26 05:09:54 +00:00
|
|
|
import { ServerContext } from '@/state/server';
|
|
|
|
import ServerContentBlock from '@/components/elements/ServerContentBlock';
|
2020-04-04 17:59:25 +00:00
|
|
|
|
|
|
|
export default () => {
|
2020-08-21 04:44:33 +00:00
|
|
|
const { clearFlashes, clearAndAddHttpError } = useFlash();
|
|
|
|
const { data: backups, error, isValidating } = getServerBackups();
|
2020-04-04 17:59:25 +00:00
|
|
|
|
2020-08-26 05:09:54 +00:00
|
|
|
const backupLimit = ServerContext.useStoreState(state => state.server.data!.featureLimits.backups);
|
|
|
|
|
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-08-26 05:09:54 +00:00
|
|
|
<ServerContentBlock title={'Backups'}>
|
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-11-09 02:09:22 +00:00
|
|
|
<p css={tw`text-center text-sm text-neutral-300`}>
|
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-08-26 05:09:54 +00:00
|
|
|
{backupLimit === 0 &&
|
2020-11-09 02:09:22 +00:00
|
|
|
<p css={tw`text-center text-sm text-neutral-300`}>
|
2020-08-21 04:44:33 +00:00
|
|
|
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-11-09 02:09:22 +00:00
|
|
|
<div css={tw`mt-6 sm:flex items-center justify-end`}>
|
|
|
|
{(backupLimit > 0 && backups.items.length > 0) &&
|
|
|
|
<p css={tw`text-sm text-neutral-300 mb-4 sm:mr-6 sm:mb-0`}>
|
|
|
|
{backups.items.length} of {backupLimit} backups have been created for this server.
|
|
|
|
</p>
|
|
|
|
}
|
|
|
|
{backupLimit > 0 && backupLimit !== backups.items.length &&
|
|
|
|
<CreateBackupButton css={tw`w-full sm:w-auto`}/>
|
|
|
|
}
|
2020-04-04 17:59:25 +00:00
|
|
|
</div>
|
|
|
|
</Can>
|
2020-08-26 05:09:54 +00:00
|
|
|
</ServerContentBlock>
|
2020-04-04 17:59:25 +00:00
|
|
|
);
|
|
|
|
};
|