|
| 1 | +import { deserialize, generatePermutations } from 'flags/next'; |
| 2 | +import { FlagValues } from 'flags/react'; |
| 3 | +import { productFlags, showFreeDeliveryBannerFlag } from '@/flags'; |
| 4 | +import { FreeDelivery } from '@/app/free-delivery'; |
| 5 | +import { DevTools } from '@/components/dev-tools'; |
| 6 | +import { Footer } from '@/components/footer'; |
| 7 | +import { Navigation } from '@/components/navigation'; |
| 8 | +import { encryptFlagValues } from 'flags'; |
| 9 | + |
| 10 | +export async function generateStaticParams() { |
| 11 | + // Returning an empty array here is important as it enables ISR, so |
| 12 | + // the various combinations stay cached after they first time they were rendered. |
| 13 | + // |
| 14 | + // return []; |
| 15 | + |
| 16 | + // Instead of returning an empty array you could also call generatePermutations |
| 17 | + // to generate the permutations upfront. |
| 18 | + const codes = await generatePermutations(productFlags); |
| 19 | + return codes.map((code) => ({ code })); |
| 20 | +} |
| 21 | + |
| 22 | +export default async function Layout(props: { |
| 23 | + children: React.ReactNode; |
| 24 | + params: Promise<{ |
| 25 | + code: string; |
| 26 | + }>; |
| 27 | +}) { |
| 28 | + const params = await props.params; |
| 29 | + const values = await deserialize(productFlags, params.code); |
| 30 | + |
| 31 | + const showFreeDeliveryBanner = await showFreeDeliveryBannerFlag( |
| 32 | + params.code, |
| 33 | + productFlags, |
| 34 | + ); |
| 35 | + |
| 36 | + const encryptedFlagValues = await encryptFlagValues(values); |
| 37 | + |
| 38 | + return ( |
| 39 | + <div className="bg-white"> |
| 40 | + <FreeDelivery show={showFreeDeliveryBanner} /> |
| 41 | + <Navigation /> |
| 42 | + {props.children} |
| 43 | + <FlagValues values={encryptedFlagValues} /> |
| 44 | + <Footer /> |
| 45 | + <DevTools /> |
| 46 | + </div> |
| 47 | + ); |
| 48 | +} |
0 commit comments