diff --git a/apps/schools/domains/employee/redux/employeeApi.ts b/apps/schools/domains/employee/redux/employeeApi.ts index bb3cd859..a494c846 100644 --- a/apps/schools/domains/employee/redux/employeeApi.ts +++ b/apps/schools/domains/employee/redux/employeeApi.ts @@ -44,7 +44,7 @@ const employeeApi = commonApi.injectEndpoints({ method: 'PATCH', body: data, }), - invalidatesTags: ['Employee'], + invalidatesTags: ['Employee', 'User'], }), deleteEmployeeById: build.mutation<{}, DeleteEmployeeByIdData>({ query: (data) => ({ diff --git a/apps/schools/domains/user/components/auth/registerForm/index.tsx b/apps/schools/domains/user/components/auth/registerForm/index.tsx index 43967535..2dd9d6c4 100644 --- a/apps/schools/domains/user/components/auth/registerForm/index.tsx +++ b/apps/schools/domains/user/components/auth/registerForm/index.tsx @@ -53,8 +53,7 @@ export const RegisterForm: React.FC = ({ onFinish, onError } name: name, email: email, } - updateProfile(updateEmail) - onFinish() + updateProfile(updateEmail).then(() => onFinish()) } }, [data, updateProfile]) diff --git a/apps/schools/domains/user/components/profile/profileEdit/index.tsx b/apps/schools/domains/user/components/profile/profileEdit/index.tsx index 7ccfc3da..3b0f27f2 100644 --- a/apps/schools/domains/user/components/profile/profileEdit/index.tsx +++ b/apps/schools/domains/user/components/profile/profileEdit/index.tsx @@ -13,11 +13,9 @@ import Link from 'next/link' import { useChangeUserProfileFormValidators } from '@domains/user/components/profile/profileEdit/hooks' import { useUpdateEmployeeProfileByIdMutation } from '@domains/employee/redux/employeeApi' import { handleSubmitForm } from '@domains/user/handlers/profile/profileEdit' -import { EventKey, useEventBus } from '@domains/common/providers/eventBusProvider' import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' export function ProfileEdit() { - const { emit } = useEventBus() const { user } = useUserProfile() const [form] = Form.useForm() @@ -52,7 +50,6 @@ export function ProfileEdit() { onFinish={() => { handleSubmitForm(user.employee_profile?.id ?? '', form, mutation).then((isSuccess) => { if (isSuccess) { - emit(EventKey.RefetchProfileQuery) router.push(RoutePath[AppRoutes.USER_LIST]) } }) diff --git a/apps/schools/domains/user/providers/authProvider.tsx b/apps/schools/domains/user/providers/authProvider.tsx index ff942eed..996a3623 100644 --- a/apps/schools/domains/user/providers/authProvider.tsx +++ b/apps/schools/domains/user/providers/authProvider.tsx @@ -3,7 +3,6 @@ import { useRouter } from 'next/router' import { useGetUserQuery } from '../redux/authenticationApi' import Cookies from 'universal-cookie' import { GetUserProfiles } from '@domains/user/redux/interfaces' -import { EventKey, useEventBus } from '@domains/common/providers/eventBusProvider' import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' export const UserProfileContext = createContext<{ @@ -24,18 +23,13 @@ export const useUserProfile = () => useContext(UserProfileContext) export const AuthProvider: React.FC = ({ children }) => { const router = useRouter() - const { on } = useEventBus() const [token, setToken] = useState('') const [user, setUser] = useState({}) - const { data, error, refetch } = useGetUserQuery({}) + const { data, error } = useGetUserQuery({}) const cookies = new Cookies() useEffect(() => { - const unsubscribeOnRefetchProfileQuery = on(EventKey.RefetchProfileQuery, () => { - refetch() - }) - if (router.pathname === RoutePath[AppRoutes.MOBILE_RECAPTCHA]) return const jwtToken = typeof window !== 'undefined' ? cookies.get('jwtToken') : null @@ -45,10 +39,6 @@ export const AuthProvider: React.FC = ({ children }) => { } else { router.push(RoutePath[AppRoutes.AUTH_SIGN_IN]) } - - return () => { - unsubscribeOnRefetchProfileQuery() - } }, []) useEffect(() => { diff --git a/apps/schools/domains/user/redux/authenticationApi.ts b/apps/schools/domains/user/redux/authenticationApi.ts index 8ecc265d..02038d89 100644 --- a/apps/schools/domains/user/redux/authenticationApi.ts +++ b/apps/schools/domains/user/redux/authenticationApi.ts @@ -9,6 +9,7 @@ const authenticationApi = commonApi.injectEndpoints({ method: 'POST', body: data, }), + invalidatesTags: ['User'], }), logout: build.mutation<{}, {}>({ query: (data) => ({ @@ -16,6 +17,7 @@ const authenticationApi = commonApi.injectEndpoints({ method: 'POST', body: data, }), + invalidatesTags: ['User'], }), getUser: build.query<{ user: GetUserProfiles }, {}>({ query: (data) => ({ @@ -23,6 +25,7 @@ const authenticationApi = commonApi.injectEndpoints({ method: 'GET', data: data, }), + providesTags: ['User'], }), updateUser: build.mutation<{ user: GetUser }, UpdateUserData>({ query: (data) => ({ @@ -30,6 +33,7 @@ const authenticationApi = commonApi.injectEndpoints({ method: 'PATCH', body: data, }), + invalidatesTags: ['User'], }), updatePassword: build.mutation<{}, UpdatePasswordData>({ query: (data) => ({ diff --git a/apps/schools/domains/user/redux/userApi.ts b/apps/schools/domains/user/redux/userApi.ts index f5463a82..2cd03145 100644 --- a/apps/schools/domains/user/redux/userApi.ts +++ b/apps/schools/domains/user/redux/userApi.ts @@ -19,6 +19,7 @@ const userApi = commonApi.injectEndpoints({ method: 'POST', body: data, }), + invalidatesTags: ['User'], }), resetPassword: build.mutation<{}, PasswordReset>({ query: (data) => ({ diff --git a/apps/schools/pages/auth/register.tsx b/apps/schools/pages/auth/register.tsx index 887bc244..88de9f5e 100644 --- a/apps/schools/pages/auth/register.tsx +++ b/apps/schools/pages/auth/register.tsx @@ -5,18 +5,15 @@ import React, { useState } from 'react' import { Dictionary } from '@reduxjs/toolkit' import { ContainerPage } from '../_app' import AuthLayout, { IAuthLayoutProps } from '../../domains/user/components/auth/containers/AuthLayout' -import { FormContainer } from '../../domains/user/components/auth/formContainer' -import { InputPhoneForm } from '../../domains/user/components/auth/sharedForms/InputPhoneForm' -import { TabsAuthAction } from '../../domains/user/components/auth/headerActions' -import { ValidatePhoneForm } from '../../domains/user/components/auth/sharedForms/ValidatePhoneForm' -import { RegisterForm } from '../../domains/user/components/auth/registerForm' -import { CENTRALIZED } from '../../domains/common/components/styles/constantStyles' +import { FormContainer } from '@domains/user/components/auth/formContainer' +import { InputPhoneForm } from '@domains/user/components/auth/sharedForms/InputPhoneForm' +import { TabsAuthAction } from '@domains/user/components/auth/headerActions' +import { ValidatePhoneForm } from '@domains/user/components/auth/sharedForms/ValidatePhoneForm' +import { RegisterForm } from '@domains/user/components/auth/registerForm' +import { CENTRALIZED } from '@domains/common/components/styles/constantStyles' import { Row } from 'antd' -import { - RegistrationDisclaimer, - RegistrationPhoneButtonLabel, -} from '../../domains/user/components/auth/constants/labels' -import { FirebaseReCaptcha } from '../../domains/user/providers/firebaseReCaptchaProvider' +import { RegistrationDisclaimer, RegistrationPhoneButtonLabel } from '@domains/user/components/auth/constants/labels' +import { FirebaseReCaptcha } from '@domains/user/providers/firebaseReCaptchaProvider' import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' const RegisterPage: ContainerPage = (props) => { @@ -56,7 +53,7 @@ const RegisterPage: ContainerPage = (props) => { <> (window.location.href = '/')} + onFinish={() => Router.push(RoutePath[AppRoutes.USER_LIST])} onError={() => { setStep('inputPhone') Router.push(RoutePath[AppRoutes.AUTH_REGISTER]) diff --git a/apps/schools/store/commonApi.ts b/apps/schools/store/commonApi.ts index 257c4acb..908a4fff 100644 --- a/apps/schools/store/commonApi.ts +++ b/apps/schools/store/commonApi.ts @@ -43,6 +43,15 @@ export const commonApi = createApi({ return headers }, }) as BaseQueryFn, - tagTypes: ['Circle', 'Student', 'StudentJoinCircleQuery', 'Organization', 'Employee', 'Ticket', 'TicketComments'], + tagTypes: [ + 'Circle', + 'Student', + 'StudentJoinCircleQuery', + 'Organization', + 'Employee', + 'Ticket', + 'TicketComments', + 'User', + ], endpoints: (_) => ({}), })