From cc4be05add69e20a0820a9469beaef67049970ec Mon Sep 17 00:00:00 2001 From: Massimo De Marchi Date: Wed, 7 Feb 2024 10:36:50 +0100 Subject: [PATCH 1/3] refactor(store pages): Move app router pages under `/Store` path --- .../(defaultLayout)/{app-router => }/Store/[[...slug]]/data.ts | 0 .../(defaultLayout)/{app-router => }/Store/[[...slug]]/page.tsx | 0 frontend/pages/Store.tsx | 2 -- frontend/pages/Store/[...slug].tsx | 2 -- 4 files changed, 4 deletions(-) rename frontend/app/(defaultLayout)/{app-router => }/Store/[[...slug]]/data.ts (100%) rename frontend/app/(defaultLayout)/{app-router => }/Store/[[...slug]]/page.tsx (100%) delete mode 100644 frontend/pages/Store.tsx delete mode 100644 frontend/pages/Store/[...slug].tsx diff --git a/frontend/app/(defaultLayout)/app-router/Store/[[...slug]]/data.ts b/frontend/app/(defaultLayout)/Store/[[...slug]]/data.ts similarity index 100% rename from frontend/app/(defaultLayout)/app-router/Store/[[...slug]]/data.ts rename to frontend/app/(defaultLayout)/Store/[[...slug]]/data.ts diff --git a/frontend/app/(defaultLayout)/app-router/Store/[[...slug]]/page.tsx b/frontend/app/(defaultLayout)/Store/[[...slug]]/page.tsx similarity index 100% rename from frontend/app/(defaultLayout)/app-router/Store/[[...slug]]/page.tsx rename to frontend/app/(defaultLayout)/Store/[[...slug]]/page.tsx diff --git a/frontend/pages/Store.tsx b/frontend/pages/Store.tsx deleted file mode 100644 index c7d38255..00000000 --- a/frontend/pages/Store.tsx +++ /dev/null @@ -1,2 +0,0 @@ -export { default } from '@templates/page'; -export { getServerSideProps } from '@templates/page/server'; diff --git a/frontend/pages/Store/[...slug].tsx b/frontend/pages/Store/[...slug].tsx deleted file mode 100644 index c7d38255..00000000 --- a/frontend/pages/Store/[...slug].tsx +++ /dev/null @@ -1,2 +0,0 @@ -export { default } from '@templates/page'; -export { getServerSideProps } from '@templates/page/server'; From a3d8e0356a3248b61a105b0b30f5cad7b7aff345 Mon Sep 17 00:00:00 2001 From: Massimo De Marchi Date: Wed, 7 Feb 2024 10:37:19 +0100 Subject: [PATCH 2/3] refactor(store pages): Drop unused stuff --- .../page/hooks/usePageTemplateProps.ts | 13 -- frontend/templates/page/index.tsx | 128 ------------------ frontend/templates/page/meta-tags.tsx | 63 --------- frontend/templates/page/server.tsx | 42 ------ 4 files changed, 246 deletions(-) delete mode 100644 frontend/templates/page/hooks/usePageTemplateProps.ts delete mode 100644 frontend/templates/page/index.tsx delete mode 100644 frontend/templates/page/meta-tags.tsx delete mode 100644 frontend/templates/page/server.tsx diff --git a/frontend/templates/page/hooks/usePageTemplateProps.ts b/frontend/templates/page/hooks/usePageTemplateProps.ts deleted file mode 100644 index 4d0dcaa6..00000000 --- a/frontend/templates/page/hooks/usePageTemplateProps.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { WithProvidersProps } from '@components/common'; -import type { WithLayoutProps } from '@layouts/default/server'; -import { useServerSideProps } from '@lib/server-side-props'; -import type { Page } from '@models/page'; - -export type PageTemplateProps = WithProvidersProps< - WithLayoutProps<{ - page: Page; - }> ->; - -export const usePageTemplateProps = () => - useServerSideProps(); diff --git a/frontend/templates/page/index.tsx b/frontend/templates/page/index.tsx deleted file mode 100644 index 03176858..00000000 --- a/frontend/templates/page/index.tsx +++ /dev/null @@ -1,128 +0,0 @@ -import { Box } from '@chakra-ui/react'; -import { BannersSection } from '@components/sections/BannersSection'; -import { FeaturedProductsSection } from '@components/sections/FeaturedProductsSection'; -import { IFixitStatsSection } from '@components/sections/IFixitStatsSection'; -import { LifetimeWarrantySection } from '@components/sections/LifetimeWarrantySection'; -import { QuoteGallerySection } from '@components/sections/QuoteGallerySection'; -import { SocialGallerySection } from '@components/sections/SocialGallerySection'; -import { SplitWithImageContentSection } from '@components/sections/SplitWithImageSection'; -import { assertNever } from '@ifixit/helpers'; -import { DefaultLayout } from '@layouts/default'; -import { - PageTemplateProps, - usePageTemplateProps, -} from './hooks/usePageTemplateProps'; -import { MetaTags } from './meta-tags'; -import { BrowseSection } from './sections/BrowseSection'; -import { HeroSection } from './sections/HeroSection'; -import { PressQuotesSection } from './sections/PressQuotesSection'; - -const PageTemplate: NextPageWithLayout = () => { - const { page } = usePageTemplateProps(); - return ( - <> - - - {page.sections.map((section) => { - switch (section.type) { - case 'Hero': { - return ; - } - case 'Browse': { - return ; - } - case 'IFixitStats': { - return ( - - ); - } - case 'SplitWithImage': { - return ( - - ); - } - case 'PressQuotes': { - return ( - - ); - } - case 'FeaturedProducts': { - return ( - - ); - } - case 'SocialGallery': { - return ( - - ); - } - case 'LifetimeWarranty': { - return ( - - ); - } - case 'Banners': { - return ( - - ); - } - case 'QuoteGallery': { - return ( - - ); - } - - default: - return assertNever(section); - } - })} - - - ); -}; - -PageTemplate.getLayout = function getLayout(page, pageProps) { - return {page}; -}; - -export default PageTemplate; diff --git a/frontend/templates/page/meta-tags.tsx b/frontend/templates/page/meta-tags.tsx deleted file mode 100644 index fe435138..00000000 --- a/frontend/templates/page/meta-tags.tsx +++ /dev/null @@ -1,63 +0,0 @@ -import { IFIXIT_ORIGIN } from '@config/env'; -import { ensureIFixitSuffix } from '@helpers/metadata-helpers'; -import { joinPaths } from '@helpers/path-helpers'; -import type { Page } from '@models/page'; -import Head from 'next/head'; - -interface MetaTagsProps { - page: Page; -} - -export function MetaTags({ page }: MetaTagsProps) { - const ogImage = findOgImage(page); - return ( - <> - - {page.metaTitle && ( - <> - - {ensureIFixitSuffix(page.metaTitle)} - - - - )} - {page.metaDescription && ( - - )} - - - {ogImage && ( - - )} - - - ); -} - -function findOgImage(page: Page) { - for (const section of page.sections) { - switch (section.type) { - case 'Hero': { - if (section.image?.url) return section.image.url; - break; - } - case 'Browse': { - if (section.image?.url) return section.image.url; - break; - } - } - } - return null; -} diff --git a/frontend/templates/page/server.tsx b/frontend/templates/page/server.tsx deleted file mode 100644 index e0aca691..00000000 --- a/frontend/templates/page/server.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import { DEFAULT_STORE_CODE } from '@config/env'; -import { invariant } from '@helpers/application-helpers'; -import { hasDisableCacheGets } from '@helpers/cache-control-helpers'; -import { ifixitOriginFromHost } from '@helpers/path-helpers'; -import { getLayoutServerSideProps } from '@layouts/default/server'; -import { findPage } from '@models/page/server'; -import { GetServerSideProps } from 'next'; -import { PageTemplateProps } from './hooks/usePageTemplateProps'; - -export const getServerSideProps: GetServerSideProps = async ( - context -) => { - const slug = context.params?.slug || []; - invariant(Array.isArray(slug), 'page slug param is missing'); - slug.unshift('Store'); - const path = `/${slug.join('/')}`; - - const layoutProps = await getLayoutServerSideProps({ - storeCode: DEFAULT_STORE_CODE, - forceMiss: hasDisableCacheGets(context), - }); - const page = await findPage({ - path, - }); - - if (page == null) { - return { - notFound: true, - }; - } - - const pageProps: PageTemplateProps = { - layoutProps, - appProps: { - ifixitOrigin: ifixitOriginFromHost(context), - }, - page, - }; - return { - props: pageProps, - }; -}; From 5e2ac9a3b56c64745854d764a262f31b077e1dce Mon Sep 17 00:00:00 2001 From: Massimo De Marchi Date: Wed, 7 Feb 2024 11:30:21 +0100 Subject: [PATCH 3/3] refactor(store pages): Remove feature flag --- frontend/.env.development | 2 +- frontend/app/(defaultLayout)/Store/[[...slug]]/page.tsx | 3 --- frontend/config/flags.ts | 4 ++-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/frontend/.env.development b/frontend/.env.development index 8188eb61..aa43f40b 100644 --- a/frontend/.env.development +++ b/frontend/.env.development @@ -14,4 +14,4 @@ NEXT_PUBLIC_ALGOLIA_PRODUCT_INDEX_NAME=dev_product_group_en NEXT_PUBLIC_DEFAULT_STORE_CODE=test # Flags -NEXT_PUBLIC_FLAG__STORE_PAGES_APP_ROUTER_ENABLED=true +# NEXT_PUBLIC_FLAG__STORE_PAGES_APP_ROUTER_ENABLED=true diff --git a/frontend/app/(defaultLayout)/Store/[[...slug]]/page.tsx b/frontend/app/(defaultLayout)/Store/[[...slug]]/page.tsx index 6054ca22..9a6296a6 100644 --- a/frontend/app/(defaultLayout)/Store/[[...slug]]/page.tsx +++ b/frontend/app/(defaultLayout)/Store/[[...slug]]/page.tsx @@ -6,7 +6,6 @@ import { QuoteGallerySection } from '@components/sections/QuoteGallerySection'; import { SocialGallerySection } from '@components/sections/SocialGallerySection'; import { SplitWithImageContentSection } from '@components/sections/SplitWithImageSection'; import { IFIXIT_ORIGIN } from '@config/env'; -import { flags } from '@config/flags'; import { ensureIFixitSuffix } from '@helpers/metadata-helpers'; import { joinPaths } from '@helpers/path-helpers'; import { assertNever, invariant } from '@ifixit/helpers'; @@ -26,8 +25,6 @@ export interface StorePageProps { } export default async function StorePage({ params }: StorePageProps) { - if (!flags.STORE_PAGES_APP_ROUTER_ENABLED) notFound(); - const page = await findPageByPath(pathFor(params.slug)); if (page == null) notFound(); diff --git a/frontend/config/flags.ts b/frontend/config/flags.ts index 636129d5..7c55c2d3 100644 --- a/frontend/config/flags.ts +++ b/frontend/config/flags.ts @@ -1,4 +1,4 @@ export const flags = { - STORE_PAGES_APP_ROUTER_ENABLED: - process.env.NEXT_PUBLIC_FLAG__STORE_PAGES_APP_ROUTER_ENABLED === 'true', + // STORE_PAGES_APP_ROUTER_ENABLED: + // process.env.NEXT_PUBLIC_FLAG__STORE_PAGES_APP_ROUTER_ENABLED === 'true', };