Skip to content

Commit

Permalink
Merge pull request #71 from premieroctet/fix/optimistic-update
Browse files Browse the repository at this point in the history
fix: optimistic update
  • Loading branch information
tlenclos authored Nov 3, 2023
2 parents dd45840 + ff5ca96 commit 797fd42
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/actions/delete-invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import db from '@/lib/db';
import * as Sentry from '@sentry/nextjs';
import { checkAuthAction, getErrorMessage } from './utils';
import { revalidateTag } from 'next/cache';
import { revalidatePath } from 'next/cache';

interface DeleteInvitationResult {
error?: {
Expand Down Expand Up @@ -32,6 +32,7 @@ export default async function deleteInvitation(
},
});

revalidatePath('/teams/[teamSlug]/settings');
return { data: { invitationId } };
} catch (err: any) {
Sentry.captureException(err);
Expand Down
1 change: 0 additions & 1 deletion src/actions/generate-api-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import db from '@/lib/db';
import * as Sentry from '@sentry/nextjs';
import jwt from 'jsonwebtoken';
import { revalidateTag } from 'next/cache';

interface APIKeyGenerationResult {
error?: {
Expand Down
1 change: 0 additions & 1 deletion src/actions/update-team-info.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use server';
import db from '@/lib/db';
import * as Sentry from '@sentry/nextjs';
import { revalidateTag } from 'next/cache';
import { checkAuthAction, checkTeamAction, getErrorMessage } from './utils';
import { Team } from '@prisma/client';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import useCustomToast from '@/hooks/useCustomToast';
import { useTransition, useOptimistic } from 'react';
import { useTransition } from 'react';
import { TeamInvitation } from '@/lib/queries';
import message from '@/messages/en';
import InvitationItem from './InvitationItem';
Expand All @@ -14,15 +14,9 @@ type Props = {
const InvitationList = ({ invitations }: Props) => {
const { successToast, errorToast } = useCustomToast();
const [isPending, startTransition] = useTransition();
const [optiInvitations, removeOptiInvitation] = useOptimistic(
invitations || [],
(state, deleteId: string) =>
[...state].filter((invitation) => invitation?.id !== deleteId)
);

const handleDeleteInvitation = async (invitation: TeamInvitation) => {
startTransition(async () => {
removeOptiInvitation(invitation?.id);
const { error } = await deleteInvitation(invitation.id);
if (error) {
errorToast(error.message);
Expand All @@ -35,7 +29,7 @@ const InvitationList = ({ invitations }: Props) => {

return (
<div className="flex flex-col gap-2 pt-4">
{optiInvitations.map((invitation: TeamInvitation) => (
{invitations.map((invitation: TeamInvitation) => (
<InvitationItem
key={invitation.id}
invitation={invitation}
Expand Down

1 comment on commit 797fd42

@vercel
Copy link

@vercel vercel bot commented on 797fd42 Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

digestclub – ./

digestclub-premieroctet.vercel.app
digestclub.vercel.app
digestclub-git-main-premieroctet.vercel.app

Please sign in to comment.