Skip to content
This repository has been archived by the owner on Dec 24, 2024. It is now read-only.

userAtom を追加 #9

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/stores/userAtom.ts
Original file line number Diff line number Diff line change
@@ -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<SigninedUser<boolean>> => {
await waitMs(2000);

const user: SigninedUser<boolean> = {
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: '[email protected]',
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);
10 changes: 10 additions & 0 deletions src/types/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,13 @@ export interface UserBase {
export type User<WithPrivate extends boolean> = UserBase &
(ActiveUserProps | OBOGMemberProps | ExternalMember) &
(WithPrivate extends true ? PrivateProps : Record<never, never>);

type IsSigninedUser = {
signined: true;
} & User<true>;

interface IsNotSigninedUser {
signined: false;
}

export type SigninedUser<T extends boolean> = T extends true ? IsSigninedUser : IsNotSigninedUser;
Loading