nfx-ui 0.23.0 → 0.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apis/ip.d.ts +0 -3
- package/dist/apis/ip.d.ts.map +1 -1
- package/dist/apis/ip.js +0 -3
- package/dist/apis/ip.js.map +1 -1
- package/dist/apis/repositories/AuthRepository.d.ts +0 -8
- package/dist/apis/repositories/AuthRepository.d.ts.map +1 -1
- package/dist/apis/repositories/AuthRepository.js +0 -14
- package/dist/apis/repositories/AuthRepository.js.map +1 -1
- package/dist/enums/auth.d.ts +2 -3
- package/dist/enums/auth.d.ts.map +1 -1
- package/dist/enums/auth.js +1 -1
- package/dist/enums/auth.js.map +1 -1
- package/dist/hooks/auth.d.ts +3 -9
- package/dist/hooks/auth.d.ts.map +1 -1
- package/dist/hooks/auth.js +35 -62
- package/dist/hooks/auth.js.map +1 -1
- package/dist/hooks/index.js +8 -8
- package/dist/providers/DataProvider/index.d.ts.map +1 -1
- package/dist/providers/DataProvider/index.js +50 -20
- package/dist/providers/DataProvider/index.js.map +1 -1
- package/dist/types/domain/auth/login.d.ts +0 -15
- package/dist/types/domain/auth/login.d.ts.map +1 -1
- package/dist/types/domain/auth/profile.d.ts +2 -0
- package/dist/types/domain/auth/profile.d.ts.map +1 -1
- package/dist/types/domain/auth/signup.d.ts +2 -6
- package/dist/types/domain/auth/signup.d.ts.map +1 -1
- package/dist/utils/domain/buildProfilePatch.d.ts.map +1 -1
- package/dist/utils/domain/buildProfilePatch.js +7 -10
- package/dist/utils/domain/buildProfilePatch.js.map +1 -1
- package/package.json +1 -1
- package/src/apis/ip.ts +0 -3
- package/src/apis/repositories/AuthRepository.ts +0 -22
- package/src/enums/auth.ts +0 -1
- package/src/hooks/auth.ts +17 -59
- package/src/providers/DataProvider/index.tsx +34 -3
- package/src/types/domain/auth/login.ts +0 -18
- package/src/types/domain/auth/profile.ts +2 -0
- package/src/types/domain/auth/signup.ts +3 -6
- package/src/utils/domain/buildProfilePatch.ts +2 -7
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { IdentityRepositories } from "@/apis";
|
|
2
2
|
import type { ReactNode } from "react";
|
|
3
3
|
|
|
4
|
-
import { useEffect } from "react";
|
|
5
|
-
import { ApiAssetRepository, ApiAuthRepository, IdentityRepositoriesContext, setIdentityRepositories } from "@/apis";
|
|
4
|
+
import { useEffect, useMemo } from "react";
|
|
5
|
+
import { ApiAssetRepository, ApiAuthRepository, IdentityRepositoriesContext, setIdentityRepositories, useAuthRepository } from "@/apis";
|
|
6
6
|
import { scheduleAccessTokenRefresh } from "@/apis/authRefresh";
|
|
7
|
-
import {
|
|
7
|
+
import { useAuthQueryScope, useCurrentProfile } from "@/hooks/auth";
|
|
8
|
+
import { configurePreferenceSync, useApplyPreferenceOnLoad } from "@/hooks/preference";
|
|
9
|
+
import { AuthStore, hasSelectedProfile, subscribeAuthStorageSync } from "@/stores/auth";
|
|
10
|
+
import { parseServerPreference, toServerPreference } from "@/stores/preference";
|
|
8
11
|
|
|
9
12
|
const defaultIdentityRepositories: IdentityRepositories = {
|
|
10
13
|
auth: new ApiAuthRepository(),
|
|
@@ -30,12 +33,40 @@ function AuthSessionBootstrap() {
|
|
|
30
33
|
return null;
|
|
31
34
|
}
|
|
32
35
|
|
|
36
|
+
function AuthPreferenceSync() {
|
|
37
|
+
const auth = useAuthRepository();
|
|
38
|
+
const { kind, isAuthValid, pID } = useAuthQueryScope();
|
|
39
|
+
const { profile } = useCurrentProfile();
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (!isAuthValid || !hasSelectedProfile(pID)) {
|
|
43
|
+
configurePreferenceSync(undefined);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
configurePreferenceSync((state) => {
|
|
47
|
+
void auth.UpdatePreference(kind, JSON.stringify(toServerPreference(state)));
|
|
48
|
+
});
|
|
49
|
+
return () => configurePreferenceSync(undefined);
|
|
50
|
+
}, [auth, kind, isAuthValid, pID]);
|
|
51
|
+
|
|
52
|
+
const serverPreference = useMemo(() => (profile?.preference ? parseServerPreference(profile.preference) : null), [profile?.preference]);
|
|
53
|
+
|
|
54
|
+
useApplyPreferenceOnLoad({
|
|
55
|
+
isAuthValid: isAuthValid && hasSelectedProfile(pID),
|
|
56
|
+
applyKey: pID,
|
|
57
|
+
serverPreference,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
33
63
|
export function DataProvider({ children, repositories }: DataProviderProps) {
|
|
34
64
|
const value = repositories ?? defaultIdentityRepositories;
|
|
35
65
|
setIdentityRepositories(value);
|
|
36
66
|
return (
|
|
37
67
|
<IdentityRepositoriesContext.Provider value={value}>
|
|
38
68
|
<AuthSessionBootstrap />
|
|
69
|
+
<AuthPreferenceSync />
|
|
39
70
|
{children}
|
|
40
71
|
</IdentityRepositoriesContext.Provider>
|
|
41
72
|
);
|
|
@@ -48,18 +48,6 @@ export namespace Login {
|
|
|
48
48
|
deviceId: string;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
export interface LoginWithGitHub {
|
|
52
|
-
code: string;
|
|
53
|
-
state: string;
|
|
54
|
-
deviceId: string;
|
|
55
|
-
signupPlatform: string;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface LinkGitHub {
|
|
59
|
-
code: string;
|
|
60
|
-
state: string;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
51
|
export interface SelectProfile {
|
|
64
52
|
profileId: string;
|
|
65
53
|
kind: ProfileKindEnum;
|
|
@@ -124,12 +112,6 @@ export namespace Login {
|
|
|
124
112
|
}
|
|
125
113
|
|
|
126
114
|
export type LoginWithPhone = LoginWithEmail;
|
|
127
|
-
export type LoginWithGitHub = LoginWithEmail;
|
|
128
|
-
|
|
129
|
-
export interface GitHubAuthorizeUrl {
|
|
130
|
-
authorizeUrl: string;
|
|
131
|
-
state: string;
|
|
132
|
-
}
|
|
133
115
|
|
|
134
116
|
export interface SelectProfile {
|
|
135
117
|
accountId: string;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { AuthSignupPlatformEnum, LanguageEnum } from "@/enums";
|
|
2
2
|
|
|
3
|
+
import type { Login } from "./login";
|
|
4
|
+
|
|
3
5
|
export namespace Signup {
|
|
4
6
|
export namespace Request {
|
|
5
7
|
export interface SendVerificationCode {
|
|
@@ -18,11 +20,6 @@ export namespace Signup {
|
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
export namespace Response {
|
|
21
|
-
export
|
|
22
|
-
accountId: string;
|
|
23
|
-
profileId: Maybe<string>;
|
|
24
|
-
accessToken: string;
|
|
25
|
-
refreshToken: string;
|
|
26
|
-
}
|
|
23
|
+
export type SignupWithEmail = Login.Response.LoginWithEmail;
|
|
27
24
|
}
|
|
28
25
|
}
|
|
@@ -2,15 +2,10 @@ import type { UserProfileEditFormData } from "@/schemas";
|
|
|
2
2
|
import type { Profile } from "@/types";
|
|
3
3
|
|
|
4
4
|
import { Language } from "@/enums";
|
|
5
|
+
import { assignIfChanged, assignNullableString, normalizeOptionalString } from "@/utils/primitive/patch";
|
|
5
6
|
import { safeNullable, safeStringable } from "@/utils/safe";
|
|
6
7
|
import { toDateInputValue } from "@/utils/time";
|
|
7
8
|
|
|
8
|
-
import { assignIfChanged, assignNullableString, normalizeOptionalString } from "../primitive/patch";
|
|
9
|
-
|
|
10
|
-
function toBirthdayISO(value: string): string {
|
|
11
|
-
return `${value}T00:00:00.000Z`;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
9
|
export function buildProfilePatch(original: Maybe<Profile.Response.ProfileBase>, form: Partial<UserProfileEditFormData>): Profile.Request.PatchProfile {
|
|
15
10
|
const patch: Profile.Request.PatchProfile = {};
|
|
16
11
|
|
|
@@ -30,7 +25,7 @@ export function buildProfilePatch(original: Maybe<Profile.Response.ProfileBase>,
|
|
|
30
25
|
const nextBirthday = normalizeOptionalString(safeStringable(form.birthday));
|
|
31
26
|
const previousBirthday = original?.birthday ? toDateInputValue(original.birthday) : null;
|
|
32
27
|
if (nextBirthday !== previousBirthday) {
|
|
33
|
-
patch.birthday = nextBirthday
|
|
28
|
+
patch.birthday = nextBirthday || null;
|
|
34
29
|
}
|
|
35
30
|
}
|
|
36
31
|
|