Skip to content

Commit

Permalink
Merge pull request #481 from lifeomic/FLME-412
Browse files Browse the repository at this point in the history
FLME-412: update account list after accepting invite
  • Loading branch information
swain committed Dec 1, 2023
2 parents bcfb860 + cee627c commit f5eb67f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
24 changes: 23 additions & 1 deletion src/components/Invitations/InviteProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,11 +29,33 @@ type ProviderProps = {
export const InviteProvider = ({ children }: ProviderProps) => {
const [inviteParams, setInviteParams] = useState<InviteParams>({});
const [lastAcceptedId, setAcceptedId] = useState<string>('');
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();
Expand Down
6 changes: 3 additions & 3 deletions src/types/rest-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,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;
}

/**
Expand Down

0 comments on commit f5eb67f

Please sign in to comment.