Skip to content

Commit

Permalink
merge with v3
Browse files Browse the repository at this point in the history
  • Loading branch information
anemne committed Sep 27, 2024
2 parents b47e733 + 6fe6675 commit 7c14ca3
Show file tree
Hide file tree
Showing 46 changed files with 407 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "../src/styles/global.css";
import localFont from "next/font/local";

const fontRecoleta = localFont({
src: "../../public/recoleta.otf",
src: "../../public/_assets/recoleta.otf",
variable: "--font-recoleta",
});

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ By using fetchWithToken, you ensure that all data fetching happens securely, wit

To enable preview functionality in the Presentation view, Sanity applies [steganography](https://www.sanity.io/docs/stega) to the string data. This manipulates the data to include invisible HTML entities to store various metadata. If the strings are used in business logic, that logic will likely break in the Presentation view. To fix this, Sanity provides the `stegaClean` utility to remove this extra metadata. An example of this in action can be found in [CompensationsPreview.tsx](src/compensations/CompensationsPreview.tsx), where JSON parsing of salary data fails without stega cleaning.

### Serving files from `/public`

As part of the Next.js middlewares setup, a [matcher config](src/middleware.ts) is used to ignore certain paths. In most cases, static files stored in the `/public` folder should not be passed through the middlewares. However, defining a regex that excludes all files from this folder can [get messy and risks excluding too many paths](https://github.com/vercel/next.js/discussions/36308#discussioncomment-9913288). To make the regex matcher cleaner, it is encouraged that no files are placed directly in `/public`. Instead, subfolders (e.g. `/public/_assets`) should be defined and then excluded explicitly. Just make sure to not collide with other router paths (prefixing with `_` reduces this risk).

### OpenGraph image customization

As part of providing the basic metadata for the [OpenGraph Protocol](https://ogp.me), a fallback image is generated if no other is specified. Fonts and background can be customized as shown below.
Expand Down
2 changes: 1 addition & 1 deletion internationalization/languageSchemaField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const languageID = "language";

const languageSchemaField = defineField({
name: languageID,
title: "Langauge",
title: "Language",
description:
"Select the language for this document from the translation menu. This field reflects the chosen language and is set automatically based on your selection.",
type: "string",
Expand Down
9 changes: 8 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@sanity/preview-url-secret": "^1.6.11",
"@sanity/react-loader": "^1.9.15",
"@sanity/vision": "^3.39.1",
"negotiator": "^0.6.3",
"next": "^14.2.13",
"next-sanity": "^7.1.4",
"next-sanity-image": "^6.1.1",
Expand All @@ -43,6 +44,7 @@
"@storybook/test": "^8.3.0",
"@storybook/test-runner": "^0.19.1",
"@types/css-modules": "^1.0.5",
"@types/negotiator": "^0.6.3",
"@types/node": "^20.16.5",
"@types/react": "^18.3.7",
"@types/react-dom": "^18.3.0",
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
4 changes: 0 additions & 4 deletions public/arrow-right.svg

This file was deleted.

4 changes: 0 additions & 4 deletions public/arrow-test.svg

This file was deleted.

1 change: 0 additions & 1 deletion public/next.svg

This file was deleted.

1 change: 0 additions & 1 deletion public/vercel.svg

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Metadata } from "next";
import { Blog } from "src/blog/Blog";
import BlogPreview from "src/blog/BlogPreview";
import CustomErrorMessage from "src/blog/components/customErrorMessage/CustomErrorMessage";
import Legal from "src/blog/components/legal/Legal";
import LegalPreview from "src/blog/components/legal/LegalPreview";
import { homeLink } from "src/blog/components/utils/linkTypes";
import Compensations from "src/compensations/Compensations";
import CompensationsPreview from "src/compensations/CompensationsPreview";
Expand All @@ -13,9 +15,13 @@ import SectionRenderer from "src/utils/renderSection";
import { fetchSeoData, generateMetadataFromSeo } from "src/utils/seo";
import { CompanyLocation } from "studio/lib/interfaces/companyDetails";
import { CompensationsPage } from "studio/lib/interfaces/compensations";
import { LegalDocument } from "studio/lib/interfaces/legalDocuments";
import { BlogPage, PageBuilder, Post } from "studio/lib/interfaces/pages";
import { CustomerCasePage } from "studio/lib/interfaces/specialPages";
import { COMPANY_LOCATIONS_QUERY } from "studio/lib/queries/admin";
import {
COMPANY_LOCATIONS_QUERY,
LEGAL_DOCUMENTS_BY_SLUG_AND_LANG_QUERY,
} from "studio/lib/queries/admin";
import {
BLOG_PAGE_QUERY,
POSTS_QUERY,
Expand All @@ -31,9 +37,7 @@ import { loadStudioQuery } from "studio/lib/store";
export const dynamic = "force-dynamic";

type Props = {
params: {
slug: string;
};
params: { lang: string; slug: string };
};

export async function generateMetadata({ params }: Props): Promise<Metadata> {
Expand All @@ -51,7 +55,8 @@ const Page404 = (
);

async function Page({ params }: Props) {
const { slug } = params;
const { lang, slug } = params;

const { perspective, isDraftMode } = getDraftModeInfo();

const [
Expand All @@ -60,6 +65,7 @@ async function Page({ params }: Props) {
initialCompensationsPage,
initialLocationsData,
initialCustomerCases,
initialLegalDocument,
] = await Promise.all([
loadStudioQuery<PageBuilder>(SLUG_QUERY, { slug }, { perspective }),
loadStudioQuery<BlogPage>(BLOG_PAGE_QUERY, { slug }, { perspective }),
Expand All @@ -78,6 +84,11 @@ async function Page({ params }: Props) {
{ slug },
{ perspective },
),
loadStudioQuery<LegalDocument>(
LEGAL_DOCUMENTS_BY_SLUG_AND_LANG_QUERY,
{ slug, language: lang },
{ perspective },
),
]);

if (initialPage.data) {
Expand Down Expand Up @@ -145,6 +156,14 @@ async function Page({ params }: Props) {
);
}

if (initialLegalDocument.data) {
return isDraftMode ? (
<LegalPreview initialDocument={initialLegalDocument} />
) : (
<Legal document={initialLegalDocument.data} />
);
}

return Page404;
}

Expand Down
27 changes: 26 additions & 1 deletion src/app/(main)/page.tsx → src/app/(main)/[lang]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { Metadata } from "next";

import CustomErrorMessage from "src/blog/components/customErrorMessage/CustomErrorMessage";
import InformationSection from "src/blog/components/informationSection/InformationSection";
import { homeLink } from "src/blog/components/utils/linkTypes";
import { getDraftModeInfo } from "src/utils/draftmode";
import SectionRenderer from "src/utils/renderSection";
import { fetchSeoData, generateMetadataFromSeo } from "src/utils/seo";
import { client } from "studio/lib/client";
import { LinkType } from "studio/lib/interfaces/navigation";
import { PageBuilder } from "studio/lib/interfaces/pages";
import { LanguageObject } from "studio/lib/interfaces/supportedLanguages";
import { LANGUAGES_QUERY } from "studio/lib/queries/languages";
import { PAGE_QUERY, SEO_PAGE_QUERY } from "studio/lib/queries/pages";
import { LANDING_PAGE_REF_QUERY } from "studio/lib/queries/siteSettings";
import { loadStudioQuery } from "studio/lib/store";
Expand Down Expand Up @@ -34,9 +39,29 @@ const pagesLink = {
internalLink: { _ref: "studio/structure/pages" },
};

const Home = async () => {
type Props = {
params: { lang: string; slug: string };
};

const Page404 = (
<CustomErrorMessage
title="404 — Something went wrong"
body="The page you are looking for does not exist. There may be an error in the URL, or the page may have been moved or deleted."
link={homeLink}
/>
);

const Home = async ({ params }: Props) => {
const { perspective, isDraftMode } = getDraftModeInfo();

const language = (
await client.fetch<LanguageObject[] | null>(LANGUAGES_QUERY)
)?.find((l) => l.id === params.lang);

if (language === undefined) {
return Page404;
}

const { data: landingId } = await loadStudioQuery<string>(
LANDING_PAGE_REF_QUERY,
{},
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { loadStudioQuery } from "studio/lib/store";
import "src/styles/global.css";

const fontRecoleta = localFont({
src: "../../public/recoleta.otf",
src: "../../public/_assets/recoleta.otf",
variable: "--font-recoleta",
});

Expand Down
4 changes: 2 additions & 2 deletions src/blog/components/loadingNews/loadingNews.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
display: block;
width: 1.5rem;
height: 1.5rem;
-webkit-mask: url("/spinner.svg") no-repeat 50% 50%;
mask: url("/spinner.svg") no-repeat 50% 50%;
-webkit-mask: url("/_assets/spinner.svg") no-repeat 50% 50%;
mask: url("/_assets/spinner.svg") no-repeat 50% 50%;
background-color: var(--primary-black);
animation: rotateSpinner 750ms linear infinite;
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/buttons/button.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
content: "";
width: 1.5rem;
height: 1.5rem;
-webkit-mask: url("/arrow-back.svg") no-repeat 50% 50%;
-webkit-mask: url("/_assets/arrow-back.svg") no-repeat 50% 50%;
background-color: var(--primary-black);
}
}
Expand All @@ -83,8 +83,8 @@
display: block;
width: 1.5rem;
height: 1.5rem;
-webkit-mask: url("/spinner.svg") no-repeat 50% 50%;
mask: url("/spinner.svg") no-repeat 50% 50%;
-webkit-mask: url("/_assets/spinner.svg") no-repeat 50% 50%;
mask: url("/_assets/spinner.svg") no-repeat 50% 50%;
background-color: var(--primary-black);
animation: rotateSpinner 750ms linear infinite;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/checkbox/checkbox.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
display: inline-block;
-webkit-mask-size: cover;
background-color: var(--primary-red-error);
-webkit-mask: url("/alert-circle.svg") no-repeat 50% 50%;
-webkit-mask: url("/_assets/alert-circle.svg") no-repeat 50% 50%;
}

@media (min-height: 1024px) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/inputField/inputField.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
display: inline-block;
-webkit-mask-size: cover;
background-color: var(--primary-red-error);
-webkit-mask: url("/alert-circle.svg") no-repeat 50% 50%;
-webkit-mask: url("/_assets/alert-circle.svg") no-repeat 50% 50%;
}

@media (min-height: 1024px) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
display: inline-block;
-webkit-mask-size: cover;
background-color: var(--primary-red-error);
-webkit-mask: url("/alert-circle.svg") no-repeat 50% 50%;
-webkit-mask: url("/_assets/alert-circle.svg") no-repeat 50% 50%;
}

@media (min-height: 1024px) {
Expand Down
7 changes: 5 additions & 2 deletions src/components/link/CustomLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ interface ICustomLink {

const CustomLink = ({ type = "link", link, isSelected }: ICustomLink) => {
const linkTitle = link.linkTitle;
// TODO: pick title based on selected language
const linkTitleValue =
(typeof linkTitle === "string" ? linkTitle : linkTitle[0].value) ?? "";
const href = getHref(link);
const newTab = link.newTab;
const target = newTab ? "_blank" : undefined;
Expand All @@ -34,7 +37,7 @@ const CustomLink = ({ type = "link", link, isSelected }: ICustomLink) => {
rel={rel}
aria-label={link.ariaLabel}
>
<span className={styles.span}>{linkTitle}</span>
<span className={styles.span}>{linkTitleValue}</span>
</Link>
<div className={styles.underline}></div>
</div>
Expand All @@ -46,7 +49,7 @@ const CustomLink = ({ type = "link", link, isSelected }: ICustomLink) => {
rel={rel}
aria-label={link.ariaLabel}
>
{linkTitle}
{linkTitleValue}
</Link>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/link/link.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
display: inline-block;
-webkit-mask-size: cover;
background-color: var(--primary-black);
-webkit-mask: url("/arrow.svg") no-repeat 50% 50%;
-webkit-mask: url("/_assets/arrow.svg") no-repeat 50% 50%;
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/components/linkButton/LinkButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ const typeClassMap: { [key in LinkButtonType]: string } = {
const LinkButton = ({ isSmall, type = "primary", link }: IButton) => {
const className = `${styles.button} ${isSmall ? styles.small : ""} ${typeClassMap[type]}`;
const href = getHref(link);
const linkTitle = link.linkTitle;
// TODO: pick title based on selected language
const linkTitleValue =
typeof linkTitle === "string" ? linkTitle : linkTitle[0].value;
return (
href && (
href &&
linkTitleValue && (
<a className={className} href={href}>
{link.linkTitle}
{linkTitleValue}
</a>
)
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/linkButton/linkButton.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
width: 1.5rem;
height: 1.5rem;
content: "";
-webkit-mask: url("/arrow.svg") no-repeat center;
-webkit-mask: url("/_assets/arrow.svg") no-repeat center;
-webkit-mask-size: cover;
mask: url("/arrow.svg") no-repeat center;
mask: url("/_assets/arrow.svg") no-repeat center;
mask-size: cover;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/components/navigation/footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ const Footer = ({
</Text>
</li>
{legalData?.map((legal) => {
const path = `legal/${legal.slug.current}`;
const link = {
_key: legal._id,
_type: legal._type,
linkTitle: legal.basicTitle,
linkType: LinkType.Internal,
internalLink: {
_ref: path,
_ref: legal.slug.current,
},
};
return (
Expand Down
4 changes: 2 additions & 2 deletions src/components/navigation/header/header.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@

.closed {
composes: button;
background: url("/menu.svg") no-repeat 50% 50%;
background: url("/_assets/menu.svg") no-repeat 50% 50%;
}

.open {
composes: button;
background: url("/menu-close.svg") no-repeat 50% 50%;
background: url("/_assets/menu-close.svg") no-repeat 50% 50%;
}
Loading

0 comments on commit 7c14ca3

Please sign in to comment.