From cd62b33adb5606dcf566e1bba8197949ba0f48a7 Mon Sep 17 00:00:00 2001 From: Wayne Date: Sat, 9 Mar 2024 13:52:23 +0900 Subject: [PATCH] Invalidate task template cache after creating a new one --- .env.production | 2 +- src/app/api/tasks/actions.ts | 18 +++++++++++++----- src/app/api/tasks/index.ts | 4 +++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.env.production b/.env.production index 395d0b9..2036fea 100644 --- a/.env.production +++ b/.env.production @@ -1,3 +1,3 @@ -API_URL=https://tsms-uat.2fi-solutions.com/back-api +API_URL=http://localhost:8090/api NEXTAUTH_SECRET=secret NEXTAUTH_URL=https://tsms-uat.2fi-solutions.com \ No newline at end of file diff --git a/src/app/api/tasks/actions.ts b/src/app/api/tasks/actions.ts index 59c1737..862cc62 100644 --- a/src/app/api/tasks/actions.ts +++ b/src/app/api/tasks/actions.ts @@ -3,6 +3,7 @@ import { serverFetchJson } from "@/app/utils/fetchUtil"; import { BASE_API_URL } from "@/config/api"; import { TaskTemplate } from "."; +import { revalidateTag } from "next/cache"; export interface NewTaskTemplateFormInputs { code: string; @@ -11,9 +12,16 @@ export interface NewTaskTemplateFormInputs { } export const saveTaskTemplate = async (data: NewTaskTemplateFormInputs) => { - return serverFetchJson(`${BASE_API_URL}/tasks/templates/new`, { - method: "POST", - body: JSON.stringify(data), - headers: { "Content-Type": "application/json" }, - }); + const newTaskTemplate = await serverFetchJson( + `${BASE_API_URL}/tasks/templates/new`, + { + method: "POST", + body: JSON.stringify(data), + headers: { "Content-Type": "application/json" }, + }, + ); + + revalidateTag("taskTemplates"); + + return newTaskTemplate; }; diff --git a/src/app/api/tasks/index.ts b/src/app/api/tasks/index.ts index ffc15f2..f5889d7 100644 --- a/src/app/api/tasks/index.ts +++ b/src/app/api/tasks/index.ts @@ -26,7 +26,9 @@ export const preloadTaskTemplates = () => { }; export const fetchTaskTemplates = cache(async () => { - return serverFetchJson(`${BASE_API_URL}/tasks/templates`); + return serverFetchJson(`${BASE_API_URL}/tasks/templates`, { + next: { tags: ["taskTemplates"] }, + }); }); export const preloadAllTasks = () => {