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

chore: FormDialogの内部処理を整理する #5321

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

AtsushiM
Copy link
Member

関連URL

概要

変更内容

確認方法

@yagimushi yagimushi force-pushed the chore-refactoring-FormDialog branch 6 times, most recently from b4642a8 to 67f0735 Compare January 23, 2025 00:46
Copy link

pkg-pr-new bot commented Jan 23, 2025

Open in Stackblitz

npm i https://pkg.pr.new/kufu/smarthr-ui@5321

commit: d77fb16

@yagimushi yagimushi force-pushed the chore-refactoring-FormDialog branch from 67f0735 to 4364bcd Compare January 23, 2025 00:50
@yagimushi yagimushi force-pushed the chore-refactoring-FormDialog branch from 7ae0086 to d77fb16 Compare January 23, 2025 06:29
@@ -24,7 +24,7 @@ export const FormDialog: React.FC<Props & ElementProps> = ({
onClickClose,
onPressEscape = onClickClose,
responseMessage,
actionDisabled = false,
actionDisabled,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actionDisabledは最終的にButtonのdisabledとして設定されるだけであり、falseを指定する意味が薄かったため、初期化しないように修正しました

if (!props.isOpen) {
return
if (props.isOpen) {
onClickClose()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

早期returnしていましたが

  • 直後の実行の条件を逆転させているだけであり、コードの理解が一手遅れる
  • !とreturn分処理が無駄になっている

というデメリットのほうが大きそうだったので調整しています

Comment on lines +88 to +111
const calcedResponseStatus = useMemo(() => {
if (!responseMessage) {
return {
isProcessing: false,
visibleMessage: false,
}
}

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

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,
}
}, [responseMessage])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

responseMessageの取り扱いが煩雑になっているので、扱いやすい形に変換、memo化するようにしました。
他コンポーネントでも同様の変換処理が有るため、別PRでカスタムhookを作成する予定です

@AtsushiM AtsushiM marked this pull request as ready for review January 23, 2025 22:37
@AtsushiM AtsushiM requested a review from a team as a code owner January 23, 2025 22:37
@AtsushiM AtsushiM requested review from yt-ymmt and uknmr and removed request for a team January 23, 2025 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant