Skip to content

Commit

Permalink
V3-cleanup-queries-structure (#723)
Browse files Browse the repository at this point in the history
* Move all admin related queries into admin.ts

* move all siteSettings related queries to siteSetting.ts

* rename oage.ts to pages.ts

* fix build fail
  • Loading branch information
anemne authored Sep 27, 2024
1 parent 98faa95 commit a1007f2
Show file tree
Hide file tree
Showing 36 changed files with 135 additions and 76 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"@sanity/preview-url-secret": "^1.6.11",
"@sanity/react-loader": "^1.9.15",
"@sanity/vision": "^3.39.1",
"@types/negotiator": "^0.6.3",
"negotiator": "^0.6.3",
"next": "^14.2.13",
"next-sanity": "^7.1.4",
Expand All @@ -45,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
2 changes: 1 addition & 1 deletion src/app/(main)/[lang]/[slug]/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
MORE_POST_PREVIEW,
POST_SLUG_QUERY,
SEO_POST_SLUG_QUERY,
} from "studio/lib/queries/page";
} from "studio/lib/queries/pages";

type Props = {
params: {
Expand Down
8 changes: 5 additions & 3 deletions src/app/(main)/[lang]/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ 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/companyDetails";
import { LEGAL_DOCUMENTS_BY_SLUG_AND_LANG_QUERY } from "studio/lib/queries/legalDocuments";
import {
COMPANY_LOCATIONS_QUERY,
LEGAL_DOCUMENTS_BY_SLUG_AND_LANG_QUERY,
} from "studio/lib/queries/admin";
import {
BLOG_PAGE_QUERY,
POSTS_QUERY,
SEO_SLUG_QUERY,
SLUG_QUERY,
} from "studio/lib/queries/page";
} from "studio/lib/queries/pages";
import {
COMPENSATIONS_PAGE_QUERY,
CUSTOMER_CASES_PAGE_QUERY,
Expand Down
4 changes: 2 additions & 2 deletions src/app/(main)/[lang]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ 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 { LANDING_PAGE_REF_QUERY } from "studio/lib/queries/navigation";
import { PAGE_QUERY, SEO_PAGE_QUERY } from "studio/lib/queries/page";
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";

export async function generateMetadata(): Promise<Metadata> {
Expand Down
16 changes: 10 additions & 6 deletions src/app/(main)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import { CompanyInfo } from "studio/lib/interfaces/companyDetails";
import { LegalDocument } from "studio/lib/interfaces/legalDocuments";
import { Navigation } from "studio/lib/interfaces/navigation";
import { SocialMediaProfiles } from "studio/lib/interfaces/socialMedia";
import { BRAND_ASSETS_QUERY } from "studio/lib/queries/brandAssets";
import { COMPANY_INFO_QUERY } from "studio/lib/queries/companyDetails";
import { LEGAL_DOCUMENTS_BY_LANG_QUERY } from "studio/lib/queries/legalDocuments";
import { NAV_QUERY } from "studio/lib/queries/navigation";
import { SOMEPROFILES_QUERY } from "studio/lib/queries/socialMediaProfiles";
import {
COMPANY_INFO_QUERY,
LEGAL_DOCUMENTS_BY_LANG_QUERY,
} from "studio/lib/queries/admin";
import {
BRAND_ASSETS_QUERY,
NAV_QUERY,
SOME_PROFILES_QUERY,
} from "studio/lib/queries/siteSettings";
import { loadStudioQuery } from "studio/lib/store";

import styles from "./layout.module.css";
Expand All @@ -37,7 +41,7 @@ export default async function Layout({
loadStudioQuery<Navigation>(NAV_QUERY, {}, { perspective }),
loadStudioQuery<CompanyInfo>(COMPANY_INFO_QUERY, {}, { perspective }),
loadStudioQuery<SocialMediaProfiles | null>(
SOMEPROFILES_QUERY,
SOME_PROFILES_QUERY,
{},
{ perspective },
),
Expand Down
41 changes: 41 additions & 0 deletions src/app/(main)/legal/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import Legal from "src/blog/components/legal/Legal";
import LegalPreview from "src/blog/components/legal/LegalPreview";
import { getDraftModeInfo } from "src/utils/draftmode";
import { LegalDocument } from "studio/lib/interfaces/legalDocuments";
import { LEGAL_DOCUMENTS_BY_SLUG_AND_LANG_QUERY } from "studio/lib/queries/admin";
import { loadStudioQuery } from "studio/lib/store";

export const dynamic = "force-dynamic";

type Props = {
params: {
id: string;
};
};

// TODO: hide from SEO???

async function Page({ params }: Props) {
const { id } = params;
const { perspective, isDraftMode } = getDraftModeInfo();

const initialDocument = await loadStudioQuery<LegalDocument>(
LEGAL_DOCUMENTS_BY_SLUG_AND_LANG_QUERY,
{ slug: id, language: "en" }, //TODO: replace this with selected language for the page
{ perspective },
);

if (!initialDocument) {
throw new Error("Page not found");
}

if (isDraftMode) {
return <LegalPreview initialDocument={initialDocument} />;
}

if (initialDocument) {
return <Legal document={initialDocument.data} />;
}
}

export default Page;
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { draftMode } from "next/headers";
import { generateMetadataFromSeo } from "src/utils/seo";
import { LanguageObject } from "studio/lib/interfaces/supportedLanguages";
import LiveVisualEditing from "studio/lib/loaders/AutomaticVisualEditing";
import { DEFAULT_LANGUAGE_QUERY } from "studio/lib/queries/languages";
import { DEFAULT_LANGUAGE_QUERY } from "studio/lib/queries/siteSettings";
import { loadStudioQuery } from "studio/lib/store";

import "src/styles/global.css";
Expand Down
4 changes: 2 additions & 2 deletions src/app/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { MetadataRoute } from "next";
import { client } from "studio/lib/client";
import { DocumentWithSlug } from "studio/lib/interfaces/global";
import { PageBuilder } from "studio/lib/interfaces/pages";
import { DOCUMENTS_WITH_SLUG_QUERY } from "studio/lib/queries/document";
import { LANDING_PAGE_QUERY } from "studio/lib/queries/navigation";
import { DOCUMENTS_WITH_SLUG_QUERY } from "studio/lib/queries/siteMap";
import { LANDING_PAGE_QUERY } from "studio/lib/queries/siteSettings";
import { token } from "studio/lib/token";

import { readBaseUrl } from "./env";
Expand Down
2 changes: 1 addition & 1 deletion src/blog/BlogPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { QueryResponseInitial, useQuery } from "@sanity/react-loader";
import { Suspense } from "react";

import { BlogPage, Post } from "studio/lib/interfaces/pages";
import { BLOG_PAGE_QUERY } from "studio/lib/queries/page";
import { BLOG_PAGE_QUERY } from "studio/lib/queries/pages";

import { Blog } from "./Blog";

Expand Down
2 changes: 1 addition & 1 deletion src/blog/components/legal/LegalPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { QueryResponseInitial, useQuery } from "@sanity/react-loader";

import { LegalDocument } from "studio/lib/interfaces/legalDocuments";
import { NAV_QUERY } from "studio/lib/queries/navigation";
import { NAV_QUERY } from "studio/lib/queries/siteSettings";

import Legal from "./Legal";

Expand Down
2 changes: 1 addition & 1 deletion src/compensations/CompensationsPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Suspense } from "react";

import { CompanyLocation } from "studio/lib/interfaces/companyDetails";
import { CompensationsPage } from "studio/lib/interfaces/compensations";
import { COMPANY_LOCATIONS_QUERY } from "studio/lib/queries/companyDetails";
import { COMPANY_LOCATIONS_QUERY } from "studio/lib/queries/admin";
import { COMPENSATIONS_PAGE_QUERY } from "studio/lib/queries/specialPages";

import Compensations from "./Compensations";
Expand Down
12 changes: 7 additions & 5 deletions src/components/navigation/footer/FooterPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { BrandAssets } from "studio/lib/interfaces/brandAssets";
import { CompanyInfo } from "studio/lib/interfaces/companyDetails";
import { Navigation } from "studio/lib/interfaces/navigation";
import { SocialMediaProfiles } from "studio/lib/interfaces/socialMedia";
import { BRAND_ASSETS_QUERY } from "studio/lib/queries/brandAssets";
import { COMPANY_INFO_QUERY } from "studio/lib/queries/companyDetails";
import { NAV_QUERY } from "studio/lib/queries/navigation";
import { SOMEPROFILES_QUERY } from "studio/lib/queries/socialMediaProfiles";
import { COMPANY_INFO_QUERY } from "studio/lib/queries/admin";
import {
BRAND_ASSETS_QUERY,
NAV_QUERY,
SOME_PROFILES_QUERY,
} from "studio/lib/queries/siteSettings";

import Footer from "./Footer";

Expand All @@ -34,7 +36,7 @@ export default function FooterPreview({
const newNav = useInitialData(NAV_QUERY, initialNav);
const newCompanyInfo = useInitialData(COMPANY_INFO_QUERY, initialCompanyInfo);
const newBrandAssets = useInitialData(BRAND_ASSETS_QUERY, initialBrandAssets);
const newSoMedata = useInitialData(SOMEPROFILES_QUERY, initialSoMe);
const newSoMedata = useInitialData(SOME_PROFILES_QUERY, initialSoMe);
// TODO: add legal preview
return (
newNav &&
Expand Down
3 changes: 1 addition & 2 deletions src/components/navigation/header/HeaderPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { QueryResponseInitial, useQuery } from "@sanity/react-loader";

import { BrandAssets } from "studio/lib/interfaces/brandAssets";
import { Navigation } from "studio/lib/interfaces/navigation";
import { BRAND_ASSETS_QUERY } from "studio/lib/queries/brandAssets";
import { NAV_QUERY } from "studio/lib/queries/navigation";
import { BRAND_ASSETS_QUERY, NAV_QUERY } from "studio/lib/queries/siteSettings";

import { Header } from "./Header";

Expand Down
2 changes: 1 addition & 1 deletion src/components/sections/article/ArticlePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Suspense } from "react";

import { PreviewProps } from "src/types/preview";
import { ArticleSection, PageBuilder } from "studio/lib/interfaces/pages";
import { PAGE_QUERY } from "studio/lib/queries/page";
import { PAGE_QUERY } from "studio/lib/queries/pages";

import Article from "./Article";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Suspense } from "react";

import { PreviewProps } from "src/types/preview";
import { CallToActionSection, PageBuilder } from "studio/lib/interfaces/pages";
import { PAGE_QUERY } from "studio/lib/queries/page";
import { PAGE_QUERY } from "studio/lib/queries/pages";

import CallToAction from "./CallToAction";

Expand Down
2 changes: 1 addition & 1 deletion src/components/sections/callout/CalloutPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Suspense } from "react";

import { PreviewProps } from "src/types/preview";
import { CalloutSection, PageBuilder } from "studio/lib/interfaces/pages";
import { PAGE_QUERY } from "studio/lib/queries/page";
import { PAGE_QUERY } from "studio/lib/queries/pages";

import Callout from "./Callout";

Expand Down
2 changes: 1 addition & 1 deletion src/components/sections/grid/GridPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Suspense } from "react";

import { PreviewProps } from "src/types/preview";
import { GridSection, PageBuilder } from "studio/lib/interfaces/pages";
import { PAGE_QUERY } from "studio/lib/queries/page";
import { PAGE_QUERY } from "studio/lib/queries/pages";

import Grid from "./Grid";

Expand Down
2 changes: 1 addition & 1 deletion src/components/sections/hero/HeroPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Suspense } from "react";

import { PreviewProps } from "src/types/preview";
import { HeroSection, PageBuilder } from "studio/lib/interfaces/pages";
import { PAGE_QUERY } from "studio/lib/queries/page";
import { PAGE_QUERY } from "studio/lib/queries/pages";

import { Hero } from "./Hero";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Suspense } from "react";

import { PreviewProps } from "src/types/preview";
import { ImageSection, PageBuilder } from "studio/lib/interfaces/pages";
import { PAGE_QUERY } from "studio/lib/queries/page";
import { PAGE_QUERY } from "studio/lib/queries/pages";

import ImageSectionComponent from "./ImageSectionComponent";

Expand Down
2 changes: 1 addition & 1 deletion src/components/sections/logoSalad/LogoSaladPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Suspense } from "react";

import { PreviewProps } from "src/types/preview";
import { LogoSaladSection, PageBuilder } from "studio/lib/interfaces/pages";
import { PAGE_QUERY } from "studio/lib/queries/page";
import { PAGE_QUERY } from "studio/lib/queries/pages";

import { LogoSalad } from "./LogoSalad";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Suspense } from "react";

import { PreviewProps } from "src/types/preview";
import { PageBuilder, TestimonialsSection } from "studio/lib/interfaces/pages";
import { PAGE_QUERY } from "studio/lib/queries/page";
import { PAGE_QUERY } from "studio/lib/queries/pages";

import { Testimonials } from "./Testimonials";

Expand Down
2 changes: 1 addition & 1 deletion src/post/PostPagePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { QueryResponseInitial, useQuery } from "@sanity/react-loader";
import { Suspense } from "react";

import { BlogPage, Post } from "studio/lib/interfaces/pages";
import { POST_SLUG_QUERY } from "studio/lib/queries/page";
import { POST_SLUG_QUERY } from "studio/lib/queries/pages";

import PostPage from "./PostPage";

Expand Down
2 changes: 1 addition & 1 deletion src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Post } from "studio/lib/interfaces/pages";
import {
CATEGORIZED_POSTS_QUERY,
COUNT_POSTS_QUERY,
} from "studio/lib/queries/page";
} from "studio/lib/queries/pages";

interface FetchResult {
data: Post[];
Expand Down
8 changes: 5 additions & 3 deletions src/utils/seo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { urlFor } from "studio/lib/image";
import { BrandAssets } from "studio/lib/interfaces/brandAssets";
import { CompanyInfo } from "studio/lib/interfaces/companyDetails";
import { DefaultSeo } from "studio/lib/interfaces/defaultSeo";
import { BRAND_ASSETS_QUERY } from "studio/lib/queries/brandAssets";
import { COMPANY_INFO_QUERY } from "studio/lib/queries/companyDetails";
import { DEFAULT_SEO_QUERY } from "studio/lib/queries/seo";
import { COMPANY_INFO_QUERY } from "studio/lib/queries/admin";
import {
BRAND_ASSETS_QUERY,
DEFAULT_SEO_QUERY,
} from "studio/lib/queries/siteSettings";
import { loadStudioQuery } from "studio/lib/store";

type SeoData = {
Expand Down
2 changes: 1 addition & 1 deletion studio/components/CustomCallToActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "sanity";

import { fetchWithToken } from "studio/lib/fetchWithToken";
import { LANDING_PAGE_REF_QUERY } from "studio/lib/queries/navigation";
import { LANDING_PAGE_REF_QUERY } from "studio/lib/queries/siteSettings";
import { buildPublishedId } from "studio/utils/documentUtils";

type CustomCallToActionsProps = ArrayOfObjectsInputProps<
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { groq } from "next-sanity";

import { companyInfoID } from "studio/schemas/documents/admin/companyInfo";

//Parent Company
export const COMPANY_INFO_QUERY = groq`*[_type == "${companyInfoID}"][0]`;

//Company Locations
export const COMPANY_LOCATIONS_QUERY = groq`*[_type == "companyLocation"]`;

//Legal Documents
export const LEGAL_DOCUMENTS_BY_LANG_QUERY = groq`*[_type == "legalDocument" && language == $language]`;

export const LEGAL_DOCUMENTS_BY_SLUG_AND_LANG_QUERY = groq`*[_type == "legalDocument" && language == $language && slug.current == $slug][0]`;
7 changes: 0 additions & 7 deletions studio/lib/queries/brandAssets.ts

This file was deleted.

7 changes: 0 additions & 7 deletions studio/lib/queries/companyDetails.ts

This file was deleted.

File renamed without changes.
10 changes: 0 additions & 10 deletions studio/lib/queries/seo.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { groq } from "next-sanity";

//Site Map
export const DOCUMENTS_WITH_SLUG_QUERY = groq`
*[defined(slug)]
`;
Loading

0 comments on commit a1007f2

Please sign in to comment.