Skip to content

Commit

Permalink
chore: cleanup types
Browse files Browse the repository at this point in the history
  • Loading branch information
BolajiAyodeji committed Jul 13, 2023
1 parent 9ea8074 commit 53cbcb4
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 122 deletions.
11 changes: 8 additions & 3 deletions components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ const Footer: React.FC<Props> = ({ lang, countries, buildLanguages }) => {
<div className="md:flex md:items-center">
<p className="mt-8 text-xs leading-5 text-gray-500 md:order-1 md:mt-0">
&copy; {new Date().getFullYear()} | {""}
{process.env.NEXT_PUBLIC_SITE_NAME ? process.env.NEXT_PUBLIC_SITE_NAME : "Examples Store, Inc"}. | All
rights reserved.
{process.env.NEXT_PUBLIC_SITE_NAME
? process.env.NEXT_PUBLIC_SITE_NAME
: "Examples Store, Inc"}
. | All rights reserved.
</p>
</div>
</div>
<div className="mt-16 border-t border-gray-900/10 pt-8 sm:mt-20 lg:mt-24 lg:flex lg:items-center lg:justify-between">
<div>
<h3 className="text-sm font-semibold leading-6 text-gray-900">{locale[lang].subscribeTitle}</h3>
<h3 className="text-sm font-semibold leading-6 text-gray-900">
{locale[lang].subscribeTitle}
</h3>
<p className="mt-2 text-sm leading-6 text-gray-600">{locale[lang].subscribeText}.</p>
</div>
<form className="mt-6 sm:flex sm:max-w-md lg:mt-0">
Expand All @@ -51,6 +55,7 @@ const Footer: React.FC<Props> = ({ lang, countries, buildLanguages }) => {
placeholder={locale[lang].subscribePlaceholder}
/>
<div className="mt-4 sm:ml-4 sm:mt-0 sm:flex-shrink-0">
{/* Handle the subcribe form yourself */}
<button
type="submit"
className="flex w-full items-center justify-center rounded-md bg-indigo-500 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
Expand Down
23 changes: 7 additions & 16 deletions pages/[countryCode]/[lang]/[product].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,10 @@ import sanityApi from "@utils/sanity/api";

type Props = {
lang: string;
countryCode: string;
country: {
code: string;
defaultLocale: string;
marketId: string;
};
clMarketId: string;
countries: Country[];
buildLanguages?: Country[];
country: Country;
product: Product;
buildLanguages?: Country[];
};

const ProductPage: React.FC<Props> = ({ lang, country, countries, buildLanguages, product }) => {
Expand Down Expand Up @@ -169,26 +163,23 @@ export const getStaticProps: GetStaticProps = async ({ params }: any) => {
const lang = params?.lang as string;
const slug = params?.product;
const countryCode = params?.countryCode as string;
const countries = _.has(sanityApi, "getAllCountries")
? await sanityApi.getAllCountries(lang)
: {};
const countries = await sanityApi.getAllCountries(lang);
const country = countries.find((country: Country) => country.code.toLowerCase() === countryCode);
const product = await sanityApi.getProduct(slug, lang);
const buildLanguages = _.compact(
process.env.BUILD_LANGUAGES?.split(",").map((l) => {
const country = countries.find((country: Country) => country.code === parseLanguageCode(l));
return !_.isEmpty(country) ? country : null;
})
);
const product = _.has(sanityApi, "getProduct") ? await sanityApi.getProduct(slug, lang) : {};

return {
props: {
lang,
countryCode,
country,
countries,
buildLanguages,
product
country,
product,
buildLanguages
},
revalidate: 60
};
Expand Down
62 changes: 21 additions & 41 deletions pages/[countryCode]/[lang]/cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@ type CartProps = {

type Props = {
lang: string;
slug: string;
clToken: string;
buildLanguages?: Country[];
countries?: any[];
country: {
code: string;
defaultLocale: string;
marketId: string;
};
countries: Country[];
country: Country;
buildLanguages: Country[];
};

const CartIframe: React.FC<CartProps> = ({ countryCode, slug, clToken }) => {
Expand Down Expand Up @@ -113,39 +107,25 @@ export const getStaticPaths: GetStaticPaths = async () => {
};

export const getStaticProps: GetStaticProps = async ({ params }) => {
try {
const lang = params?.lang as string;
const countryCode = params?.countryCode as string;
const countries = _.has(sanityApi, "getAllCountries")
? await sanityApi.getAllCountries(lang)
: {};
const country = countries.find(
(country: Country) => country.code.toLowerCase() === countryCode
);
const buildLanguages = _.compact(
process.env.BUILD_LANGUAGES?.split(",").map((l) => {
const country = countries.find((country: Country) => country.code === parseLanguageCode(l));
return !_.isEmpty(country) ? country : null;
})
);
const lang = params?.lang as string;
const countryCode = params?.countryCode as string;
const countries = await sanityApi.getAllCountries(lang);
const country = countries.find((country: Country) => country.code.toLowerCase() === countryCode);
const buildLanguages = _.compact(
process.env.BUILD_LANGUAGES?.split(",").map((l) => {
const country = countries.find((country: Country) => country.code === parseLanguageCode(l));
return !_.isEmpty(country) ? country : null;
})
);

return {
props: {
buildLanguages,
lang,
countries,
country
}
};
} catch (err: any) {
console.error(err);
return {
props: {
errors: err.message
},
revalidate: 60
};
}
return {
props: {
lang,
countries,
country,
buildLanguages
}
};
};

export default ShoppingBagPage;
80 changes: 27 additions & 53 deletions pages/[countryCode]/[lang]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,19 @@ import { useGetToken } from "@hooks/GetToken";
import Page from "@components/Page";
import Hero from "@components/Hero";
import Taxonomies from "@components/Taxonomies";
import { Country } from "@typings/models";
import { Country, Taxonomy } from "@typings/models";
import { parseLanguageCode } from "@utils/parser";
import sanityApi from "@utils/sanity/api";

type Props = {
lang: string;
buildLanguages?: Country[];
country: {
code: string;
defaultLocale: string;
marketId: string;
};
countries?: any[];
taxonomies: any;
countries: Country[];
country: Country;
taxonomies: Taxonomy[];
buildLanguages: Country[];
};

const HomePage: NextPage<Props> = ({
lang,
buildLanguages = [],
country,
countries = [],
taxonomies
}) => {
const HomePage: NextPage<Props> = ({ lang, countries, country, taxonomies, buildLanguages }) => {
const languageCode = parseLanguageCode(lang, "toLowerCase", true);
const countryCode = country?.code.toLowerCase() as string;
const clMarketId = country?.marketId as string;
Expand Down Expand Up @@ -63,42 +53,26 @@ export const getStaticPaths: GetStaticPaths = async () => {
};

export const getStaticProps: GetStaticProps = async ({ params }) => {
try {
const lang = params?.lang as string;
const countryCode = params?.countryCode as string;
const countries = _.has(sanityApi, "getAllCountries")
? await sanityApi.getAllCountries(lang)
: {};
const country = countries.find(
(country: Country) => country.code.toLowerCase() === countryCode
);
const buildLanguages = _.compact(
process.env.BUILD_LANGUAGES?.split(",").map((l) => {
const country = countries.find((country: Country) => country.code === parseLanguageCode(l));
return !_.isEmpty(country) ? country : null;
})
);
const taxonomies = _.has(sanityApi, "getAllTaxonomies")
? await sanityApi.getAllTaxonomies(country.catalog.id, lang)
: {};
const lang = params?.lang as string;
const countryCode = params?.countryCode as string;
const countries = await sanityApi.getAllCountries(lang);
const country = countries.find((country: Country) => country.code.toLowerCase() === countryCode);
const taxonomies = await sanityApi.getAllTaxonomies(country.catalog.id, lang);
const buildLanguages = _.compact(
process.env.BUILD_LANGUAGES?.split(",").map((l) => {
const country = countries.find((country: Country) => country.code === parseLanguageCode(l));
return !_.isEmpty(country) ? country : null;
})
);

return {
props: {
lang,
countries,
country,
buildLanguages,
taxonomies
},
revalidate: 60
};
} catch (err: any) {
console.error(err);
return {
props: {
errors: err.message
},
revalidate: 60
};
}
return {
props: {
lang,
countries,
country,
taxonomies,
buildLanguages
},
revalidate: 60
};
};
2 changes: 0 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import Countries from "@components/Countries";
import sanityApi from "@utils/sanity/api";

type Props = {
[key: string]: any;
lang: string;
countries: any[];
};

Expand Down
15 changes: 8 additions & 7 deletions typings/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface Country {
domain: string;
catalog: Catalog;
image: Image;
marketId: string;
}

export interface Catalog {
Expand All @@ -25,13 +26,6 @@ export interface Taxon {
taxons: Taxon[];
}

export interface Image {
file?: {
url?: string;
};
url: string;
}

export interface Product {
name: string;
slug: string;
Expand All @@ -53,6 +47,13 @@ export interface Size {
name: string;
}

export interface Image {
file?: {
url?: string;
};
url: string;
}

export interface SelectorObject {
code: string;
imageUrl: string;
Expand Down

0 comments on commit 53cbcb4

Please sign in to comment.