Skip to content

Commit

Permalink
chore: リファクタリング
Browse files Browse the repository at this point in the history
  • Loading branch information
AtsushiM committed Jan 23, 2025
1 parent 920d9f6 commit 39c13ac
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import React, { type FC, type PropsWithChildren, type ReactNode, useCallback, useMemo } from 'react'

import { type ResponseMessageType, useResponseMessage } from '../../../libs/responseMessage'
import { Button } from '../../Button'
import { Cluster, Stack } from '../../Layout'
import { ResponseMessage } from '../../ResponseMessage'
Expand All @@ -11,7 +12,6 @@ import { DialogHeader, type Props as DialogHeaderProps } from '../DialogHeader'
import { dialogContentInner } from '../dialogInnerStyle'

import type { DecoratorsType } from '../../../types'
import { type ResponseMessageType, useResponseMessage } from '../../../libs/responseMessage'

export type BaseProps = PropsWithChildren<
DialogHeaderProps &
Expand Down Expand Up @@ -97,7 +97,7 @@ export const ActionDialogContentInner: FC<ActionDialogContentInnerProps> = ({
className={styles.buttonArea}
/>
</Cluster>
{calcedResponseStatus.visibleMessage && (
{calcedResponseStatus.status && (
<div className={styles.message}>
<ResponseMessage type={calcedResponseStatus.status} role="alert">
{calcedResponseStatus.message}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import React, {
} from 'react'
import { tv } from 'tailwind-variants'

import { type ResponseMessageType, useResponseMessage } from '../../../libs/responseMessage'
import { Button } from '../../Button'
import { Cluster, Stack } from '../../Layout'
import { ResponseMessage } from '../../ResponseMessage'
Expand All @@ -17,7 +18,6 @@ import { DialogHeader, type Props as DialogHeaderProps } from '../DialogHeader'
import { dialogContentInner } from '../dialogInnerStyle'

import type { DecoratorsType } from '../../../types'
import { type ResponseMessageType, useResponseMessage } from '../../../libs/responseMessage'

export type BaseProps = PropsWithChildren<
DialogHeaderProps &
Expand Down Expand Up @@ -122,7 +122,7 @@ export const FormDialogContentInner: FC<FormDialogContentInnerProps> = ({
className={styles.buttonArea}
/>
</Cluster>
{calcedResponseStatus.visibleMessage && (
{calcedResponseStatus.status && (
<div className={styles.message}>
<ResponseMessage type={calcedResponseStatus.status} role="alert">
{calcedResponseStatus.message}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { ComponentProps, FC, ReactNode, useMemo } from 'react'
import innerText from 'react-innertext'
import { tv } from 'tailwind-variants'

import { type ResponseMessageType, useResponseMessage } from '../../../libs/responseMessage'
import { Button, BaseProps as ButtonProps } from '../../Button'
import { FaCircleCheckIcon, FaFilterIcon, FaRotateLeftIcon } from '../../Icon'
import { Cluster, Stack } from '../../Layout'
Expand All @@ -14,7 +15,6 @@ import { DropdownContent } from '../DropdownContent'
import { DropdownTrigger } from '../DropdownTrigger'

import type { DecoratorType, DecoratorsType } from '../../../types'
import { type ResponseMessageType, useResponseMessage } from '../../../libs/responseMessage'

type Props = {
isFiltered?: boolean
Expand Down Expand Up @@ -216,7 +216,7 @@ export const FilterDropdown: FC<Props & ElementProps> = ({
</DropdownCloser>
</Cluster>
</Cluster>
{calcedResponseStatus.visibleMessage && (
{calcedResponseStatus.status && (
<div className={messageStyle}>
<ResponseMessage type={calcedResponseStatus.status} role="alert">
{calcedResponseStatus.message}
Expand Down
2 changes: 1 addition & 1 deletion packages/smarthr-ui/src/components/FloatArea/FloatArea.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { ComponentPropsWithoutRef, FC, ReactNode, useMemo } from 'react'
import { tv } from 'tailwind-variants'

import { type ResponseMessageTypeWithoutProcessing } from '../../libs/responseMessage'
import { AbstractSize, CharRelativeSize } from '../../themes/createSpacing'
import { Gap } from '../../types'
import { type ResponseMessageTypeWithoutProcessing } from '../../libs/responseMessage'
import { Base } from '../Base'
import { Cluster } from '../Layout'
import { ResponseMessage } from '../ResponseMessage'
Expand Down
11 changes: 6 additions & 5 deletions packages/smarthr-ui/src/libs/responseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,25 @@ export const useResponseMessage = (responseMessage: ResponseMessageType | undefi
if (!responseMessage) {
return {
isProcessing: false,
visibleMessage: false,
status: null,
message: '',
}
}

if (responseMessage.status === 'processing') {
return {
isProcessing: true,
visibleMessage: false,
status: null,
message: '',
}
}

return {
isProcessing: false,
visibleMessage: true,
// HINT: statusがprocessingではない === success or errorであることが確定する
// success or error の場合、text属性も必ず存在する
status: responseMessage.status as 'success' | 'error',
message: (responseMessage as { text: string }).text,
status: responseMessage.status,
message: responseMessage.text,
}
}, [responseMessage])

Expand Down

0 comments on commit 39c13ac

Please sign in to comment.