From 95212af935760fe34473fa4377969d24b4e06ca8 Mon Sep 17 00:00:00 2001 From: yusheng chen Date: Fri, 4 Apr 2025 21:11:33 +0800 Subject: [PATCH] refactor: type improvement of file `oneMoreStep.tsx` (#17431) --- web/app/signin/oneMoreStep.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/web/app/signin/oneMoreStep.tsx b/web/app/signin/oneMoreStep.tsx index 7607598bfb..a78a3ab3b1 100644 --- a/web/app/signin/oneMoreStep.tsx +++ b/web/app/signin/oneMoreStep.tsx @@ -1,5 +1,5 @@ 'use client' -import React, { useEffect, useReducer } from 'react' +import React, { type Reducer, useEffect, useReducer } from 'react' import { useTranslation } from 'react-i18next' import Link from 'next/link' import useSWR from 'swr' @@ -20,7 +20,14 @@ type IState = { timezone: string } -const reducer = (state: IState, action: any) => { +type IAction = + | { type: 'failed', payload: null } + | { type: 'invitation_code', value: string } + | { type: 'interface_language', value: string } + | { type: 'timezone', value: string } + | { type: 'formState', value: 'processing' } + +const reducer: Reducer = (state: IState, action: IAction) => { switch (action.type) { case 'invitation_code': return { ...state, invitation_code: action.value } @@ -120,7 +127,7 @@ const OneMoreStep = () => { defaultValue={LanguagesSupported[0]} items={languages.filter(item => item.supported)} onSelect={(item) => { - dispatch({ type: 'interface_language', value: item.value }) + dispatch({ type: 'interface_language', value: item.value as typeof LanguagesSupported[number] }) }} /> @@ -134,7 +141,7 @@ const OneMoreStep = () => { defaultValue={state.timezone} items={timezones} onSelect={(item) => { - dispatch({ type: 'timezone', value: item.value }) + dispatch({ type: 'timezone', value: item.value as typeof state.timezone }) }} />