Skip to content

Commit 26e8258

Browse files
committed
Add purgin and revalidation
1 parent eaaab34 commit 26e8258

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/globals/MainPage.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { Directions, ImagePositionMainPageDesktop } from '@/lib/selects'
33
import { colorField } from '@lib/utils/colors'
44
import { MainPageImage } from '@/payload-types'
55
import draftAccess from '@/lib/utils/access'
6+
import { routing } from '@/i18n/routing'
7+
import { revalidatePath } from 'next/cache'
8+
import purgeRoute from '@/lib/utils/purge'
69

710
const MainPage: GlobalConfig = {
811
slug: 'mainPageImages',
@@ -222,6 +225,24 @@ const MainPage: GlobalConfig = {
222225
},
223226
},
224227
},
228+
hooks: {
229+
afterChange: [
230+
async ({ req, doc }) => {
231+
if (doc._status === 'published') {
232+
const updatedLocale = req.locale
233+
if (updatedLocale === 'all')
234+
routing.locales.map(async (locale) => {
235+
revalidatePath(`/${locale}`)
236+
await purgeRoute(`${locale}`)
237+
})
238+
else {
239+
revalidatePath(`/${updatedLocale}`)
240+
await purgeRoute(`${updatedLocale}`)
241+
}
242+
}
243+
},
244+
],
245+
},
225246
}
226247

227248
export default MainPage

src/globals/Sculptures.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { GlobalConfig } from 'payload'
22
import { colorField } from '@/lib/utils/colors'
33
import draftAccess from '@/lib/utils/access'
4+
import { routing } from '@/i18n/routing'
5+
import { revalidatePath } from 'next/cache'
6+
import purgeRoute from '@/lib/utils/purge'
47

58
export const Sculptures: GlobalConfig = {
69
slug: 'sculpture',
@@ -97,4 +100,22 @@ export const Sculptures: GlobalConfig = {
97100
},
98101
},
99102
},
103+
hooks: {
104+
afterChange: [
105+
async ({ req, doc }) => {
106+
if (doc._status === 'published') {
107+
const updatedLocale = req.locale
108+
if (updatedLocale === 'all')
109+
routing.locales.map(async (locale) => {
110+
revalidatePath(`/${locale}/sculptures`)
111+
await purgeRoute(`${locale}/sculptures`)
112+
})
113+
else {
114+
revalidatePath(`/${updatedLocale}/sculptures`)
115+
await purgeRoute(`${updatedLocale}/sculptures`)
116+
}
117+
}
118+
},
119+
],
120+
},
100121
}

0 commit comments

Comments
 (0)