Skip to content
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

fix: StepFormDialogにuseResponseMessageを適用する #5388

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React, {
} from 'react'

import { type DecoratorsType, useDecorators } from '../../../hooks/useDecorators'
import { type ResponseMessageType, useResponseMessage } from '../../../hooks/useResponseMessage'
import { Button } from '../../Button'
import { Cluster, Stack } from '../../Layout'
import { ResponseMessage } from '../../ResponseMessage'
Expand All @@ -19,8 +20,6 @@ import { dialogContentInner } from '../dialogInnerStyle'

import { StepFormDialogContext, StepItem } from './StepFormDialogProvider'

import type { ResponseMessageType } from '../../../types'

export type BaseProps = PropsWithChildren<
DialogHeaderProps &
DialogBodyProps & {
Expand Down Expand Up @@ -122,8 +121,6 @@ export const StepFormDialogContentInner: FC<StepFormDialogContentInnerProps> = (
setCurrentStep(stepQueue.current.pop() ?? firstStep)
}, [firstStep, stepQueue, onClickBack, setCurrentStep])

const isRequestProcessing = responseMessage && responseMessage.status === 'processing'

const classNames = useMemo(() => {
const { wrapper, actionArea, buttonArea, message } = dialogContentInner()

Expand All @@ -138,6 +135,8 @@ export const StepFormDialogContentInner: FC<StepFormDialogContentInnerProps> = (
const decorated = useDecorators<DecoratorKeyTypes>(DECORATOR_DEFAULT_TEXTS, decorators)
const actionText = activeStep === stepLength ? submitLabel : decorated.nextButtonLabel

const calcedResponseStatus = useResponseMessage(responseMessage)

return (
// eslint-disable-next-line smarthr/a11y-heading-in-sectioning-content
<Section>
Expand All @@ -156,7 +155,7 @@ export const StepFormDialogContentInner: FC<StepFormDialogContentInnerProps> = (
{activeStep > 1 && (
<Button
onClick={handleBackAction}
disabled={isRequestProcessing}
disabled={calcedResponseStatus.isProcessing}
className="smarthr-ui-Dialog-backButton"
>
{decorated.backButtonLabel}
Expand All @@ -165,7 +164,7 @@ export const StepFormDialogContentInner: FC<StepFormDialogContentInnerProps> = (
<Cluster gap={BUTTON_COLUMN_GAP} className={classNames.buttonArea}>
<Button
onClick={handleCloseAction}
disabled={closeDisabled || isRequestProcessing}
disabled={closeDisabled || calcedResponseStatus.isProcessing}
className="smarthr-ui-Dialog-closeButton"
>
{decorated.closeButtonLabel}
Expand All @@ -174,17 +173,17 @@ export const StepFormDialogContentInner: FC<StepFormDialogContentInnerProps> = (
type="submit"
variant={actionTheme}
disabled={actionDisabled}
loading={isRequestProcessing}
loading={calcedResponseStatus.isProcessing}
className="smarthr-ui-Dialog-actionButton"
>
{actionText}
</Button>
</Cluster>
</Cluster>
{(responseMessage?.status === 'success' || responseMessage?.status === 'error') && (
{calcedResponseStatus.message && (
<div className={classNames.message}>
<ResponseMessage type={responseMessage.status} role="alert">
{responseMessage.text}
<ResponseMessage type={calcedResponseStatus.status} role="alert">
{calcedResponseStatus.message}
</ResponseMessage>
</div>
)}
Expand Down