MCPcopy Create free account
hub / github.com/apitable/apitable / useUserRequest

Function useUserRequest

packages/datasheet/src/pc/hooks/use_user_request.ts:43–635  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

41 * This hook encapsulates the logic related to user request processing
42 */
43export const useUserRequest = () => {
44 const dispatch = useDispatch();
45 const urlParams = getSearchParams();
46 const reference = urlParams.get('reference') || undefined;
47 const activeSpaceId = useAppSelector((state) => state.space.activeId);
48 const userInfo = useAppSelector((state: IReduxState) => state.user.info);
49 const inviteEmailInfo = useAppSelector((state: IReduxState) => state.invite.inviteEmailInfo);
50 const { join } = useLinkInvite();
51 /**
52 * Get the login status and update the user information into userMe in redux if you are already logged in.
53 * @param {{spaceId?: string | null, nodeId?: string | null}} locateIdMap
54 * @param {boolean} filter
55 * @returns {Promise<import("axios").AxiosResponse<IApiWrapper & {data: IUserInfo}>>}
56 */
57 const getLoginStatusReq = (locateIdMap: { spaceId?: string | null; nodeId?: string | null } = { spaceId: '', nodeId: '' }, filter = false) => {
58 return Api.getUserMe(locateIdMap, filter).then((res) => {
59 const { data, success, code, message } = res.data;
60 if (success) {
61 dispatch(
62 batchActions(
63 [StoreActions.setIsLogin(true), StoreActions.setUserMe(data), StoreActions.setLoading(false), StoreActions.updateUserInfoErr(null)],
64 LOGIN_SUCCESS,
65 ),
66 );
67 if (!activeSpaceId) {
68 dispatch(StoreActions.setActiveSpaceId(data.spaceId));
69 }
70 if (locateIdMap.spaceId) {
71 NotificationStore.joinSpace(locateIdMap.spaceId);
72 }
73 return data;
74 }
75 if (code === StatusCode.INVALID_SPACE) {
76 Modal.error({
77 title: t(Strings.get_verification_code_err_title),
78 content: t(Strings.enter_unactive_space_err_message),
79 okText: t(Strings.submit),
80 onOk: () => {
81 Router.push(Navigation.HOME);
82 },
83 });
84 return;
85 }
86 dispatch(StoreActions.setLoading(false));
87 dispatch(
88 StoreActions.updateUserInfoErr({
89 code,
90 msg: message,
91 }),
92 );
93 return;
94 });
95 };
96
97 /**
98 * Direct login/registration
99 */
100 const loginOrRegisterReq = (loginData: ApiInterface.ISignIn) => {

Callers 15

MailBindPhoneFunction · 0.90
AddressSideFunction · 0.90
TemplateCentreFunction · 0.90
TemplatePreviewFunction · 0.90
TemplateUseButtonFunction · 0.90
ForgetPasswordFunction · 0.90
SignUpFunction · 0.90
LoginFunction · 0.90
useMountShareFunction · 0.90
IdentifyingCodeInputFunction · 0.90
ModifyPasswordFunction · 0.90
AccountManagerFunction · 0.90

Calls 4

useDispatchFunction · 0.90
getSearchParamsFunction · 0.90
useLinkInviteFunction · 0.90
getMethod · 0.65

Tested by

no test coverage detected