Skip to content

Commit

Permalink
Add "Set Credentials to Default" btn on "No storage" screen
Browse files Browse the repository at this point in the history
  • Loading branch information
gdbroman committed Oct 12, 2023
1 parent 056ed80 commit d625bae
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const AccountStorageSection = ({ account }: Props) => {
});
}, [token, ships, account.serverId]);

const onClickRestartStorage = () => {
const onClickRestartStorage = async () => {
const selectedShip = ships.find((ship) => ship.patp === account.serverId);

if (!token) return;
Expand Down
10 changes: 8 additions & 2 deletions hosting-holium-com/src/pages/account/storage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,19 @@ const S3StoragePresenter = () => {
getAndSetS3Info(token, selectedShip.id.toString());
}, [token, ships, selectedShipId]);

const onClickRestartStorage = () => {
const onClickRestartStorage = async () => {
const selectedShip = ships.find((ship) => ship.id === selectedShipId);

if (!token) return;
if (!selectedShip) return;

return thirdEarthApi.setStorage(token, selectedShip.id.toString());
try {
await thirdEarthApi.setStorage(token, selectedShip.id.toString());
} catch (e) {
setError('Failed to restart storage.');
}

return;
};

return (
Expand Down
37 changes: 17 additions & 20 deletions shared/src/onboarding/components/storage/StorageTroubleshoot.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useState } from 'react';

import { Button, Flex, Spinner, Text } from '@holium/design-system/general';
import { Flex, Spinner } from '@holium/design-system/general';

import { AccountDialogTableRow } from '../../components/AccountDialogTableRow';
import { GrayButton } from '../ChangeButton';

type Props = {
onClick: () => Promise<string> | undefined;
onClick: () => Promise<void>;
};

type DebugState = 'uninitialized' | 'restarting' | 'restarted';
Expand All @@ -16,11 +16,11 @@ export const StorageTroubleshoot = ({ onClick }: Props) => {
const getDebugElement = () => {
switch (debugState) {
case 'uninitialized':
return <Text.Body>Set Credentials to Default</Text.Body>;
return 'Set Credentials to Default';
case 'restarting':
return <Spinner size={16} />;
case 'restarted':
return <Text.Body>Restarted</Text.Body>;
return 'Restarted';
default:
return null;
}
Expand All @@ -33,20 +33,17 @@ export const StorageTroubleshoot = ({ onClick }: Props) => {
};

return (
<AccountDialogTableRow title="Troubleshoot">
<Flex flex={1} justifyContent="flex-end">
<Button.Secondary
type="button"
width="191px"
height="28px"
alignItems="center"
justifyContent="center"
disabled={['restarting', 'restarted'].includes(debugState)}
onClick={handleOnClick}
>
{getDebugElement()}
</Button.Secondary>
</Flex>
</AccountDialogTableRow>
<Flex flex={1} justifyContent="flex-end">
<GrayButton
type="button"
width="195px"
alignItems="center"
justifyContent="center"
disabled={['restarting', 'restarted'].includes(debugState)}
onClick={handleOnClick}
>
{getDebugElement()}
</GrayButton>
</Flex>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Props = {
};
isLoading: boolean;
error: string | undefined;
onClickRestartStorage: () => Promise<string> | undefined;
onClickRestartStorage: () => Promise<void>;
setSelectedShipId: (newId: number) => void;
onClickPurchaseId: () => void;
onClickUploadPier: () => void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorBox } from '@holium/design-system/general';
import { ErrorBox, Flex } from '@holium/design-system/general';

import { AccountDialogDescription } from '../../components/AccountDialog.styles';
import { AccountDialogTableRow } from '../../components/AccountDialogTableRow';
Expand All @@ -21,7 +21,7 @@ type Props = {
minioUsage: number;
};
error: string | undefined;
onClickRestartStorage: () => Promise<string> | undefined;
onClickRestartStorage: () => Promise<void>;
};

export const AccountStorageDialogBody = ({
Expand All @@ -35,9 +35,12 @@ export const AccountStorageDialogBody = ({
}: Props) => {
if (error) {
return (
<AccountDialogTable>
<>
<ErrorBox>{error}</ErrorBox>
</AccountDialogTable>
<Flex flexDirection="column" alignItems="center">
<StorageTroubleshoot onClick={onClickRestartStorage} />
</Flex>
</>
);
}

Expand All @@ -56,7 +59,9 @@ export const AccountStorageDialogBody = ({
</AccountDialogDescription>
</AccountDialogTableRow>
<StoragePassword storagePassword={storagePassword} />
<StorageTroubleshoot onClick={onClickRestartStorage} />
<AccountDialogTableRow title="Troubleshoot">
<StorageTroubleshoot onClick={onClickRestartStorage} />
</AccountDialogTableRow>
</AccountDialogTable>
);
};
2 changes: 1 addition & 1 deletion shared/src/onboarding/dialogs/Login.WEB.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const AccountStorageDialogStory: ComponentStory<
<AccountStorageDialog
ships={[thirdEarthMockShip]}
selectedShipId={0}
onClickRestartStorage={() => Promise.resolve('')}
onClickRestartStorage={() => Promise.resolve()}
setSelectedShipId={() => {}}
onClickPurchaseId={() => {}}
onClickUploadPier={() => {}}
Expand Down

0 comments on commit d625bae

Please sign in to comment.