Skip to content

Commit

Permalink
fix(condo): INFRA-574 fixed CORS in cc
Browse files Browse the repository at this point in the history
fix(next): INFRA-574 fixed cache

fix(next): INFRA-574 removed unused code

feat(condo): INFRA-574 updated submodule cc

refactor(condo): INFRA-574 some refactoring

fix(next): INFRA-574 fixed AuthProvider and OrganizationProvider
  • Loading branch information
Alllex202 committed Oct 29, 2024
1 parent ca8cbe0 commit e6e0db1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion apps/callcenter
8 changes: 2 additions & 6 deletions apps/condo/domains/common/utils/next/apollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ const cacheConfig: InitCacheConfig = (cacheOptions) => {
}
}

function getApiUrl (): string {
return apolloGraphQLUrl
}

export const apolloHelperOptions = {
uri: getApiUrl,
uri: apolloGraphQLUrl,
cacheConfig,
}
}
24 changes: 10 additions & 14 deletions packages/next/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DocumentNode } from 'graphql'
import { gql } from 'graphql-tag'
import get from 'lodash/get'
import { NextPage } from 'next'
import React, { createContext, useContext, useEffect, useState, useCallback } from 'react'
import React, { createContext, useContext, useEffect, useState, useCallback, useMemo } from 'react'

import { DEBUG_RERENDERS, DEBUG_RERENDERS_BY_WHY_DID_YOU_RENDER, preventInfinityLoop, getContextIndependentWrappedInitialProps } from './_utils'
import { useApolloClient, useMutation, useQuery } from './apollo'
Expand Down Expand Up @@ -263,7 +263,7 @@ const AuthProvider: React.FC = ({ children }) => {

const { data, loading: userLoading, refetch } = useQuery(USER_QUERY)

const [user, setUser] = useState(get(data, 'authenticatedUser', null))
const user = useMemo(() => get(data, 'authenticatedUser' || null), [data])

const refetchAuth = useCallback(async () => {
await refetch()
Expand All @@ -277,7 +277,6 @@ const AuthProvider: React.FC = ({ children }) => {

if (item) {
await apolloClient.clearStore()
setUser(item)
}
},
onError: (error) => {
Expand All @@ -286,24 +285,21 @@ const AuthProvider: React.FC = ({ children }) => {
})

const [signOutMutation, { loading: signOutLoading }] = useMutation(SIGNOUT_MUTATION, {
onCompleted: async (data) => {
const success = get(data, ['unauthenticateUser', 'success'])
if (success) setUser(null)

onCompleted: async () => {
removeCookieEmployeeId()
await apolloClient.clearStore()
await apolloClient.cache.reset()
apolloClient.cache.writeQuery({
query: USER_QUERY,
data: {
authenticatedUser: null,
},
})
},
onError: (error) => {
console.error(error)
},
})

useEffect(() => {
if (!userLoading) {
setUser(get(data, 'authenticatedUser', null))
}
}, [data, userLoading])

return (
<AuthContext.Provider
value={{
Expand Down
1 change: 1 addition & 0 deletions packages/next/organization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ const OrganizationProvider: React.FC<OrganizationProviderProps> = ({
if (auth.isLoading) return
if (!auth.user && activeEmployee !== null) {
setActiveEmployee(null)
setActiveEmployeeId(null)
}
}, [auth.user])

Expand Down

0 comments on commit e6e0db1

Please sign in to comment.