diff --git a/src/components/Invitations/InviteProvider.tsx b/src/components/Invitations/InviteProvider.tsx index a99c99f0..ab42f64b 100644 --- a/src/components/Invitations/InviteProvider.tsx +++ b/src/components/Invitations/InviteProvider.tsx @@ -3,7 +3,7 @@ import { Alert } from 'react-native'; import { t } from '../../../lib/i18n'; import { inviteNotifier } from './InviteNotifier'; import { useAuth } from '../../hooks/useAuth'; -import { useRestMutation } from '../../hooks/rest-api'; +import { useRestCache, useRestMutation } from '../../hooks/rest-api'; type InviteParams = { inviteId?: string; @@ -29,11 +29,33 @@ type ProviderProps = { export const InviteProvider = ({ children }: ProviderProps) => { const [inviteParams, setInviteParams] = useState({}); const [lastAcceptedId, setAcceptedId] = useState(''); + const cache = useRestCache(); const { isLoading, isSuccess, isError, reset, mutateAsync } = useRestMutation( 'PATCH /v1/invitations/:inviteId', { // Do not include account header on this request. axios: { headers: { 'LifeOmic-Account': '' } }, + onSuccess: (data) => { + // Add the new account to the account list. + cache.updateCache( + 'GET /v1/accounts', + {}, + { + accounts: [ + { + id: data.account, + name: data.accountName, + type: 'PAID', + logo: undefined, + features: [], + products: [], + trialActive: false, + trialEndDate: undefined, + }, + ], + }, + ); + }, }, ); const { authResult, refreshForInviteAccept } = useAuth(); diff --git a/src/types/rest-types.ts b/src/types/rest-types.ts index 310c62e5..e717cc29 100644 --- a/src/types/rest-types.ts +++ b/src/types/rest-types.ts @@ -7,12 +7,12 @@ export interface Account { id: string; name: string; type: string; - description: string; - logo: string; + description?: string; + logo?: string; products: string[]; features: string[]; trialActive: boolean; - trialEndDate: string; + trialEndDate?: string; } /**