From 176ae2403c8108997327fe7e4b0187d931376875 Mon Sep 17 00:00:00 2001 From: satooru65536 Date: Mon, 20 May 2024 13:38:30 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20userAtom=20=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/userAtom.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ src/types/user.ts | 10 ++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/stores/userAtom.ts diff --git a/src/stores/userAtom.ts b/src/stores/userAtom.ts new file mode 100644 index 0000000..c9b4183 --- /dev/null +++ b/src/stores/userAtom.ts @@ -0,0 +1,42 @@ +import { atom } from 'jotai'; +import { loadable } from 'jotai/utils'; +import { type SigninedUser } from '@/types/user'; +import { waitMs } from '@/utils/promise'; + +const fetchUser = async (): Promise> => { + await waitMs(2000); + + const user: SigninedUser = { + signined: true, + id: '0000-0000-0000-0000', + firstName: '智', + lastName: '佐藤', + firstNameKana: 'さとる', + lastNameKana: 'さとう', + skills: ['JavaScript', 'TypeScript', 'React'], + graduationYear: 2027, + slackName: '', + iconUrl: 'https://via.placeholder.com/50', + type: 'active', + grade: 'B1', + position: '部員', + studentNumber: 'k23075', + birthdate: '2005-01-05', + email: 'satooru@syscat.net', + gender: '男', + phoneNumber: '090-0000-0000', + currentAddress: { + address: '愛知県名古屋市', + postalCode: '460-0000', + }, + homeAddress: { + address: '愛知県名古屋市', + postalCode: '460-0000', + }, + }; + + return user; +}; + +const userAtom = atom(async () => await fetchUser()); +export const userAtomLoadable = loadable(userAtom); diff --git a/src/types/user.ts b/src/types/user.ts index 008be5f..cc43329 100644 --- a/src/types/user.ts +++ b/src/types/user.ts @@ -53,3 +53,13 @@ export interface UserBase { export type User = UserBase & (ActiveUserProps | OBOGMemberProps | ExternalMember) & (WithPrivate extends true ? PrivateProps : Record); + +type IsSigninedUser = { + signined: true; +} & User; + +interface IsNotSigninedUser { + signined: false; +} + +export type SigninedUser = T extends true ? IsSigninedUser : IsNotSigninedUser;