-
Notifications
You must be signed in to change notification settings - Fork 17
fix(Tablet): correctly process error in dialog action #758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import {useState, type ReactNode} from 'react'; | ||
|
|
||
| import {Button, type ButtonProps} from '@gravity-ui/uikit'; | ||
|
|
||
| import {CriticalActionDialog} from '../CriticalActionDialog'; | ||
|
|
||
| interface ButtonWithConfirmDialogProps<T, K> { | ||
| children: ReactNode; | ||
| onConfirmAction: () => Promise<T>; | ||
| onConfirmActionSuccess?: (() => Promise<K>) | VoidFunction; | ||
| dialogContent: string; | ||
| buttonDisabled?: ButtonProps['disabled']; | ||
| buttonView?: ButtonProps['view']; | ||
| buttonClassName?: ButtonProps['className']; | ||
| } | ||
|
|
||
| export function ButtonWithConfirmDialog<T, K>({ | ||
| children, | ||
| onConfirmAction, | ||
| onConfirmActionSuccess, | ||
| dialogContent, | ||
| buttonDisabled = false, | ||
| buttonView = 'action', | ||
| buttonClassName, | ||
| }: ButtonWithConfirmDialogProps<T, K>) { | ||
| const [isConfirmDialogVisible, setIsConfirmDialogVisible] = useState(false); | ||
| const [buttonLoading, setButtonLoading] = useState(false); | ||
|
|
||
| const handleConfirmAction = async () => { | ||
| setButtonLoading(true); | ||
| await onConfirmAction(); | ||
| setButtonLoading(false); | ||
| }; | ||
|
|
||
| const handleConfirmActionSuccess = async () => { | ||
| if (onConfirmActionSuccess) { | ||
| setButtonLoading(true); | ||
|
|
||
| try { | ||
| await onConfirmActionSuccess(); | ||
| } catch { | ||
| } finally { | ||
| setButtonLoading(false); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| const handleConfirmActionError = () => { | ||
| setButtonLoading(false); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for wrapper
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It contains two components
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops, overlooked |
||
| <CriticalActionDialog | ||
| visible={isConfirmDialogVisible} | ||
| text={dialogContent} | ||
| onConfirm={handleConfirmAction} | ||
| onConfirmActionSuccess={handleConfirmActionSuccess} | ||
| onConfirmActionError={handleConfirmActionError} | ||
| onClose={() => { | ||
| setIsConfirmDialogVisible(false); | ||
| }} | ||
| /> | ||
| <Button | ||
| onClick={() => setIsConfirmDialogVisible(true)} | ||
| view={buttonView} | ||
| disabled={buttonDisabled} | ||
| loading={!buttonDisabled && buttonLoading} | ||
| className={buttonClassName} | ||
| > | ||
| {children} | ||
| </Button> | ||
| </> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,21 @@ | ||
| .ydb-critical-dialog { | ||
| width: 252px !important; | ||
| width: 400px; | ||
|
|
||
| &__warning-icon { | ||
| margin-right: 16px; | ||
| } | ||
|
|
||
| &__error-icon { | ||
| height: 24px; | ||
| margin-right: 16px; | ||
|
|
||
| color: var(--ydb-color-status-red); | ||
| } | ||
|
|
||
| &__body { | ||
| display: flex; | ||
| align-items: center; | ||
|
|
||
| padding: 16px 16px 0; | ||
| } | ||
|
|
||
| & .yc-dialog-footer { | ||
| padding: 20px 4px 4px; | ||
| } | ||
|
|
||
| & .yc-dialog-footer__children { | ||
| display: none; | ||
| } | ||
|
|
||
| & .yc-dialog-footer__button { | ||
| box-sizing: border-box; | ||
| min-width: 120px; | ||
| margin: 0; | ||
| } | ||
|
|
||
| & .yc-dialog-footer__button_action_cancel { | ||
| margin-right: 4px; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "default-error": "Something went wrong, action cannot be completed", | ||
| "no-rights-error": "You don't have enough rights to complete the operation", | ||
|
|
||
| "button-confirm": "Confirm", | ||
| "button-cancel": "Cancel", | ||
| "button-close": "Close" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import {registerKeysets} from '../../../utils/i18n'; | ||
|
|
||
| import en from './en.json'; | ||
|
|
||
| const COMPONENT = 'ydb-critical-action-dialog'; | ||
|
|
||
| export const criticalActionDialogKeyset = registerKeysets(COMPONENT, {en}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if no
onConfirmActionSuccessis passed andhandleConfirmActionErrordidn't fired?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, in this case button in infinite loading state, I will fix it