-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
57 lines (48 loc) · 1.12 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React from "react";
import { GAuthToken, IUser } from "../../types";
export type IAuthState = {
user: IUser | null;
accessToken: string | null;
refreshToken: string | null;
};
export interface IAuthContext {
auth: IAuthState;
dispatchAuth: React.Dispatch<AuthActions>;
}
export type ActionMap<M extends { [index: string]: any }> = {
[Key in keyof M]: M[Key] extends undefined
? {
type: Key;
}
: {
type: Key;
payload: M[Key];
};
};
export type AuthActions = ActionMap<UserPayload>[keyof ActionMap<UserPayload>];
export enum AuthAct {
LOGIN = "LOGIN",
LOGOUT = "LOGOUT",
RESTORE = "RESTORE",
REFRESH = "REFRESH",
UPDATE = "UPDATE",
VOTE_VDP = "VOTE_VDP",
VOTE_AIRSHOW = "VOTE_AIRSHOW",
}
export type UserPayload = {
[AuthAct.LOGIN]: IAuthState;
[AuthAct.RESTORE]: IAuthState;
[AuthAct.LOGOUT]: undefined;
[AuthAct.REFRESH]: {
accessToken: string,
refreshToken: string,
};
[AuthAct.UPDATE]: IUser;
[AuthAct.VOTE_AIRSHOW]: string;
[AuthAct.VOTE_VDP]: string;
};
export const loggedOutState: IAuthState = {
user: null,
accessToken: null,
refreshToken: null,
};