mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-11-26 16:52:06 +05:30
Implemented loading state, when user clicked on the restore button
This commit is contained in:
parent
55d767b65c
commit
dd506b894c
@ -8,6 +8,13 @@ import AccountDeleted from './AccountDeleted';
|
|||||||
|
|
||||||
storiesOf('Components/Profile', module).add('AccountDeleted', () => (
|
storiesOf('Components/Profile', module).add('AccountDeleted', () => (
|
||||||
<ProfileLayout>
|
<ProfileLayout>
|
||||||
<AccountDeleted onRestore={action('onRestore')} />
|
<AccountDeleted
|
||||||
|
onRestore={() =>
|
||||||
|
new Promise((resolve) => {
|
||||||
|
action('onRestore')();
|
||||||
|
setTimeout(resolve, 500);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
</ProfileLayout>
|
</ProfileLayout>
|
||||||
));
|
));
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { ComponentType } from 'react';
|
import React, { ComponentType, useCallback, useState } from 'react';
|
||||||
import { FormattedMessage as Message } from 'react-intl';
|
import { FormattedMessage as Message } from 'react-intl';
|
||||||
import { Helmet } from 'react-helmet-async';
|
import { Helmet } from 'react-helmet-async';
|
||||||
|
|
||||||
@ -7,10 +7,20 @@ import { Button } from 'app/components/ui/form';
|
|||||||
import styles from './accountDeleted.scss';
|
import styles from './accountDeleted.scss';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onRestore?: () => void;
|
onRestore?: () => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AccountDeleted: ComponentType<Props> = ({ onRestore }) => {
|
const AccountDeleted: ComponentType<Props> = ({ onRestore }) => {
|
||||||
|
const [isSubmitted, setIsSubmitted] = useState<boolean>(false);
|
||||||
|
const onRestoreClick = useCallback(() => {
|
||||||
|
if (!onRestore) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsSubmitted(true);
|
||||||
|
onRestore().finally(() => setIsSubmitted(false));
|
||||||
|
}, [onRestore]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.wrapper}>
|
<div className={styles.wrapper}>
|
||||||
<Message key="accountDeleted" defaultMessage="Account is deleted">
|
<Message key="accountDeleted" defaultMessage="Account is deleted">
|
||||||
@ -36,7 +46,7 @@ const AccountDeleted: ComponentType<Props> = ({ onRestore }) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Button onClick={onRestore} color="black" small>
|
<Button onClick={onRestoreClick} color="black" small loading={isSubmitted}>
|
||||||
<Message key="restoreAccount" defaultMessage="Restore account" />
|
<Message key="restoreAccount" defaultMessage="Restore account" />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user