Skip to content

Commit 48d8964

Browse files
committed
fix a MobX warning and improve typing
1 parent c46e43b commit 48d8964

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

packages/flat-components/src/components/LoginPage/LoginAccount/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface LoginAccountProps {
3636

3737
// history props
3838
password?: string;
39-
accountHistory?: Array<{ key: string; password: string; countryCode: string | null }> | [];
39+
accountHistory?: Array<{ key: string; password: string; countryCode?: string | null }> | [];
4040
onHistoryChange?: (options: any) => void;
4141
}
4242

packages/flat-components/src/components/LoginPage/LoginWithPassword/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export interface LoginWithPasswordProps {
4141
buttons?: LoginButtonProviderType[];
4242
privacyURL?: LoginAgreementProps["privacyURL"];
4343
serviceURL?: LoginAgreementProps["serviceURL"];
44-
accountHistory: Array<{ key: string; password: string; countryCode: string | null }> | [];
44+
accountHistory: Array<{ key: string; password: string; countryCode?: string | null }>;
4545
login: (type: PasswordLoginType, key: LoginKeyType, password: string) => Promise<boolean>;
4646
register: () => void;
4747
onClickButton: LoginButtonsProps["onClick"];
@@ -89,8 +89,9 @@ export const LoginWithPassword: React.FC<LoginWithPasswordProps> = ({
8989
const [agreed, setAgreed] = useState(false);
9090
const [clickedLogin, setClickedLogin] = useState(false);
9191
const [clickedReset, setClickedReset] = useState(false);
92+
const firstAccount = accountHistory.length > 0 ? accountHistory[0] : null;
9293
const [countryCode, setCountryCode] = useState(
93-
accountHistory?.[0]?.countryCode || defaultCountryCode,
94+
(firstAccount && firstAccount.countryCode) || defaultCountryCode,
9495
);
9596
const [type, setType] = useState(PasswordLoginType.Phone);
9697

@@ -102,8 +103,8 @@ export const LoginWithPassword: React.FC<LoginWithPasswordProps> = ({
102103
const [isAccountValidated, setIsAccountValidated] = useState(false);
103104

104105
const defaultValues = {
105-
key: accountHistory?.[0]?.key || "",
106-
password: accountHistory?.[0]?.password || "",
106+
key: firstAccount?.key || "",
107+
password: firstAccount?.password || "",
107108
code: undefined,
108109
};
109110
const [password, setPassword] = useState(defaultValues.password);

packages/flat-stores/src/global-store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class GlobalStore {
3838

3939
// login with password
4040
public currentAccount: Account | null = null;
41-
public accountHistory: Account[] | [] = [];
41+
public accountHistory: Account[] = [];
4242

4343
public whiteboardRoomUUID: string | null = null;
4444
public whiteboardRoomToken: string | null = null;

0 commit comments

Comments
 (0)