Skip to content

Commit

Permalink
Handle PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nalanj committed Nov 27, 2024
1 parent dd2465b commit b6fd8c6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/webapp/src/hooks/useConnections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function useConnections(queries: GetConnections['Querystring']) {
return { loading, error: error?.json, data, hasNext, offset: size, setOffset: setSize, mutate };
}

export function invalidateConnections(cache: Cache, mutate: ReturnType<typeof useSWRConfig>['mutate']) {
export function clearConnectionsCache(cache: Cache, mutate: ReturnType<typeof useSWRConfig>['mutate']) {
for (const key of cache.keys()) {
if (key.includes('/api/v1/connections?')) {
void mutate(key, undefined);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useToast } from '../../../../../hooks/useToast';
import { useNavigate } from 'react-router-dom';
import { useSWRConfig } from 'swr';
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogTitle, DialogTrigger } from '../../../../../components/ui/Dialog';
import { invalidateConnections } from '../../../../../hooks/useConnections';
import { clearConnectionsCache } from '../../../../../hooks/useConnections';

export const DeleteIntegrationButton: React.FC<{ env: string; integration: ApiIntegration }> = ({ env, integration }) => {
const { toast } = useToast();
Expand All @@ -27,7 +27,7 @@ export const DeleteIntegrationButton: React.FC<{ env: string; integration: ApiIn
toast({ title: `Integration "${integration.unique_key}" has been deleted`, variant: 'success' });
void mutate((key) => typeof key === 'string' && key.startsWith(`/api/v1/integrations`), undefined);

invalidateConnections(cache, mutate);
clearConnectionsCache(cache, mutate);

navigate(`/${env}/integrations`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useToast } from '../../../hooks/useToast';
import { Helmet } from 'react-helmet';
import { ErrorPageComponent } from '../../../components/ErrorComponent';
import { useSWRConfig } from 'swr';
import { invalidateConnections } from '../../../hooks/useConnections';
import { clearConnectionsCache } from '../../../hooks/useConnections';

export const ShowIntegration: React.FC = () => {
const { providerConfigKey } = useParams();
Expand Down Expand Up @@ -63,16 +63,14 @@ export const ShowIntegration: React.FC = () => {
const onEvent: OnConnectEvent = useCallback(
(event) => {
if (event.type === 'close') {
invalidateConnections(cache, mutate);

if (hasConnected.current) {
toast.toast({ title: `Connected to ${data?.integration.unique_key}`, variant: 'success' });
navigate(`/${env}/connections/${data?.integration.unique_key}/${hasConnected.current}`);
}
} else if (event.type === 'connect') {
console.log('connected', event);

invalidateConnections(cache, mutate);
clearConnectionsCache(cache, mutate);
hasConnected.current = event.payload.connectionId;
}
},
Expand Down

0 comments on commit b6fd8c6

Please sign in to comment.