2022-03-07 14:50:00 +00:00
|
|
|
import {
|
|
|
|
GetCurrenciesQuery,
|
|
|
|
GetLanguagesQuery,
|
|
|
|
GetWebsiteInterfaceQuery,
|
2022-03-31 12:59:31 +00:00
|
|
|
} from "graphql/generated";
|
|
|
|
import { getReadySdk } from "graphql/sdk";
|
2022-05-08 19:37:41 +00:00
|
|
|
import { Immutable } from "helpers/types";
|
2022-03-27 15:01:14 +00:00
|
|
|
import { GetStaticPropsContext } from "next";
|
2022-03-07 14:50:00 +00:00
|
|
|
|
2022-05-08 19:37:41 +00:00
|
|
|
export type AppStaticProps = Immutable<{
|
2022-05-14 23:15:57 +00:00
|
|
|
langui: NonNullable<
|
|
|
|
NonNullable<
|
|
|
|
GetWebsiteInterfaceQuery["websiteInterfaces"]
|
|
|
|
>["data"][number]["attributes"]
|
2022-03-31 12:59:31 +00:00
|
|
|
>;
|
2022-05-14 23:15:57 +00:00
|
|
|
currencies: NonNullable<GetCurrenciesQuery["currencies"]>["data"];
|
|
|
|
languages: NonNullable<GetLanguagesQuery["languages"]>["data"];
|
2022-05-08 19:37:41 +00:00
|
|
|
}>;
|
2022-03-07 14:50:00 +00:00
|
|
|
|
|
|
|
export async function getAppStaticProps(
|
2022-03-27 15:01:14 +00:00
|
|
|
context: GetStaticPropsContext
|
2022-03-07 14:50:00 +00:00
|
|
|
): Promise<AppStaticProps> {
|
2022-03-31 12:59:31 +00:00
|
|
|
const sdk = getReadySdk();
|
|
|
|
const languages = (await sdk.getLanguages()).languages;
|
|
|
|
|
|
|
|
if (languages?.data) {
|
|
|
|
languages.data.sort((a, b) =>
|
|
|
|
a.attributes && b.attributes
|
|
|
|
? a.attributes.localized_name.localeCompare(b.attributes.localized_name)
|
|
|
|
: 0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const currencies = (await sdk.getCurrencies()).currencies;
|
|
|
|
if (currencies?.data) {
|
|
|
|
currencies.data.sort((a, b) =>
|
|
|
|
a.attributes && b.attributes
|
|
|
|
? a.attributes.code.localeCompare(b.attributes.code)
|
|
|
|
: 0
|
|
|
|
);
|
|
|
|
}
|
2022-03-07 14:50:00 +00:00
|
|
|
|
2022-03-31 12:59:31 +00:00
|
|
|
const langui = (
|
|
|
|
await sdk.getWebsiteInterface({
|
|
|
|
language_code: context.locale ?? "en",
|
|
|
|
})
|
|
|
|
).websiteInterfaces?.data[0].attributes;
|
2022-03-07 14:50:00 +00:00
|
|
|
|
2022-05-08 19:37:41 +00:00
|
|
|
const appStaticProps: AppStaticProps = {
|
|
|
|
langui: langui ?? {},
|
|
|
|
currencies: currencies?.data ?? [],
|
|
|
|
languages: languages?.data ?? [],
|
2022-03-07 14:50:00 +00:00
|
|
|
};
|
2022-05-08 19:37:41 +00:00
|
|
|
|
|
|
|
return appStaticProps;
|
2022-03-07 14:50:00 +00:00
|
|
|
}
|