signal-desktop/ts/components/AvatarModalButtons.tsx

55 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-08-06 00:17:05 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React, { useState } from 'react';
import { Button, ButtonVariant } from './Button';
import { ConfirmDiscardDialog } from './ConfirmDiscardDialog';
import type { LocalizerType } from '../types/Util';
2021-08-06 00:17:05 +00:00
import { Modal } from './Modal';
export type PropsType = {
hasChanges: boolean;
i18n: LocalizerType;
onCancel: () => unknown;
onSave: () => unknown;
};
2022-11-18 00:45:19 +00:00
export function AvatarModalButtons({
2021-08-06 00:17:05 +00:00
hasChanges,
i18n,
onCancel,
onSave,
2022-11-18 00:45:19 +00:00
}: PropsType): JSX.Element {
2021-08-06 00:17:05 +00:00
const [confirmDiscardAction, setConfirmDiscardAction] = useState<
(() => unknown) | undefined
>(undefined);
return (
<Modal.ButtonFooter>
<Button
onClick={() => {
if (hasChanges) {
setConfirmDiscardAction(() => onCancel);
} else {
onCancel();
}
}}
variant={ButtonVariant.Secondary}
>
{i18n('cancel')}
</Button>
<Button disabled={!hasChanges} onClick={onSave}>
{i18n('save')}
</Button>
{confirmDiscardAction && (
<ConfirmDiscardDialog
i18n={i18n}
onDiscard={confirmDiscardAction}
onClose={() => setConfirmDiscardAction(undefined)}
/>
)}
</Modal.ButtonFooter>
);
2022-11-18 00:45:19 +00:00
}