From 1c5cb18d302ea068205941239912ad77aafe596d Mon Sep 17 00:00:00 2001 From: Maxim Snesarev Date: Thu, 2 Apr 2026 22:39:37 +0300 Subject: [PATCH] Refactor product page and improve type safety in Footer and Header components - Updated the product page to filter size options, ensuring only string types are included. - Modified Footer and Header components to allow nullable types for phone, email, whatsapp, and footerText properties. - Enhanced Dockerfile to optimize dependency installation and build process using Turbo for improved performance. --- .../app/(frontend)/product/[slug]/page.tsx | 2 +- apps/web/src/components/Footer.tsx | 8 ++--- apps/web/src/components/Header.tsx | 2 +- docker/Dockerfile | 34 +++++++++---------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/apps/web/src/app/(frontend)/product/[slug]/page.tsx b/apps/web/src/app/(frontend)/product/[slug]/page.tsx index a48176d..97fc25d 100644 --- a/apps/web/src/app/(frontend)/product/[slug]/page.tsx +++ b/apps/web/src/app/(frontend)/product/[slug]/page.tsx @@ -109,7 +109,7 @@ export default async function ProductPage({ params }: ProductPageProps) { }); const sizeOptions: string[] = Array.isArray(product.sizeOptions) - ? product.sizeOptions + ? product.sizeOptions.filter((s): s is string => typeof s === "string") : []; const specs: { label: string; value: string }[] = []; diff --git a/apps/web/src/components/Footer.tsx b/apps/web/src/components/Footer.tsx index 0044e5c..a48bd31 100644 --- a/apps/web/src/components/Footer.tsx +++ b/apps/web/src/components/Footer.tsx @@ -4,10 +4,10 @@ import config from "@payload-config"; export async function Footer() { let settings: { - phone?: string; - email?: string; - whatsapp?: string; - footerText?: string; + phone?: string | null; + email?: string | null; + whatsapp?: string | null; + footerText?: string | null; } = {}; try { const payload = await getPayload({ config }); diff --git a/apps/web/src/components/Header.tsx b/apps/web/src/components/Header.tsx index 24b64cf..3cdd52d 100644 --- a/apps/web/src/components/Header.tsx +++ b/apps/web/src/components/Header.tsx @@ -4,7 +4,7 @@ import config from "@payload-config"; import { MobileMenu } from "./MobileMenu"; export async function Header() { - let settings: { phone?: string } = {}; + let settings: { phone?: string | null } = {}; try { const payload = await getPayload({ config }); settings = await payload.findGlobal({ slug: "site-settings" }); diff --git a/docker/Dockerfile b/docker/Dockerfile index 40fed0e..7e3b162 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,24 +1,24 @@ FROM node:22-alpine AS base +RUN apk add --no-cache libc6-compat RUN corepack enable && corepack prepare pnpm@10 --activate WORKDIR /app -# Install dependencies -FROM base AS deps -COPY pnpm-lock.yaml pnpm-workspace.yaml package.json ./ -COPY apps/web/package.json apps/web/package.json -COPY packages/shared/package.json packages/shared/package.json -COPY packages/tsconfig/package.json packages/tsconfig/package.json -COPY packages/eslint-config/package.json packages/eslint-config/package.json +# Prune the monorepo for only the packages @advdoors/web needs +FROM base AS pruner +RUN pnpm add -g turbo@^2 +COPY . . +RUN turbo prune @advdoors/web --docker + +# Install dependencies using the pruned lockfile (cached unless deps change) +FROM base AS builder +COPY --from=pruner /app/out/json/ . +COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml RUN pnpm install --frozen-lockfile -# Build -FROM base AS builder -COPY --from=deps /app/node_modules ./node_modules -COPY --from=deps /app/apps/web/node_modules ./apps/web/node_modules -COPY --from=deps /app/packages ./packages -COPY . . +# Copy pruned source and build via Turbo +COPY --from=pruner /app/out/full/ . ENV NEXT_TELEMETRY_DISABLED=1 -RUN pnpm --filter @advdoors/web build +RUN pnpm turbo build --filter=@advdoors/web # Production FROM base AS runner @@ -28,9 +28,9 @@ ENV NEXT_TELEMETRY_DISABLED=1 RUN addgroup --system --gid 1001 nodejs && \ adduser --system --uid 1001 nextjs -COPY --from=builder /app/apps/web/.next/standalone ./ -COPY --from=builder /app/apps/web/.next/static ./apps/web/.next/static -COPY --from=builder /app/apps/web/public ./apps/web/public +COPY --from=builder --chown=nextjs:nodejs /app/apps/web/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/apps/web/.next/static ./apps/web/.next/static +COPY --from=builder --chown=nextjs:nodejs /app/apps/web/public ./apps/web/public USER nextjs EXPOSE 3000