From 2183cdbbb69ae46f24b81e336967c2e27a68e75a Mon Sep 17 00:00:00 2001 From: Ben Marshall Date: Tue, 11 Apr 2023 14:58:30 -0500 Subject: [PATCH] build(clean up): code clean-up --- .../gutenberg/gravity-forms/Form/Form.tsx | 18 +- app/wordpress/[...slug]/page.tsx | 9 +- app/wordpress/page.tsx | 5 +- functions/jsonToCssVariables.ts | 7 +- .../wordpress/menus/formatNavigationMenu.ts | 8 +- .../postTypes/getPostTypeStaticPaths.ts | 1 + lib/wordpress/connector.ts | 7 +- package-lock.json | 208 ++++++++---------- package.json | 7 +- types/wordpress/menus.d.ts | 2 +- types/wordpress/posts.d.ts | 8 + 11 files changed, 137 insertions(+), 143 deletions(-) create mode 100644 types/wordpress/posts.d.ts diff --git a/app/components/gutenberg/gravity-forms/Form/Form.tsx b/app/components/gutenberg/gravity-forms/Form/Form.tsx index d98ec76..c2b4cf7 100644 --- a/app/components/gutenberg/gravity-forms/Form/Form.tsx +++ b/app/components/gutenberg/gravity-forms/Form/Form.tsx @@ -30,23 +30,22 @@ export default function Form(props: { formId: string }) { // Form success and error message. const success = () => { messageApi.open({ - type: 'success', - content: 'Your form was successfully submitted', + type: "success", + content: "Your form was successfully submitted", }); }; const error = () => { messageApi.open({ - type: 'error', - content: 'Something went wrong please try again', + type: "error", + content: "Something went wrong please try again", }); }; - // On form Submit. // @TODO: Add type for function parameter const onFinish = async (values: any) => { - setLoading(true) + setLoading(true); const response = await insertGfFormEntry(formId, values, formData); /** * @TODO: Find a way to add support for server side validation error if possible. @@ -54,13 +53,13 @@ export default function Form(props: { formId: string }) { */ if (response?.errors?.length > 0) { // Set form error as per the requirement. - error() + error(); } else { // Navigate user to success page or set a success message as required - success() + success(); form.resetFields(); } - setLoading(false) + setLoading(false); }; // Form Layout for Fields @@ -84,6 +83,7 @@ export default function Form(props: { formId: string }) { const fetchData = async () => { const response = await getGfFormById(formId); if (response) { + // @ts-ignore setFormData(response.gfForm); } }; diff --git a/app/wordpress/[...slug]/page.tsx b/app/wordpress/[...slug]/page.tsx index f835d21..53b6a36 100644 --- a/app/wordpress/[...slug]/page.tsx +++ b/app/wordpress/[...slug]/page.tsx @@ -20,13 +20,18 @@ import Blocks from "@/components/gutenberg/Blocks/Blocks"; * Import type definitions */ import { GutenbergGlobalBlockProps } from "@/types/gutenberg"; +import { WordPressPostProps } from "@/types/wordpress/posts"; export default async function Page({ params }: { params: { slug: string } }) { let entity; const slug = Array.isArray(params.slug) ? params.slug.join("/") : params.slug; - const { page } = await connector(queryPageById, { id: slug }); + const { page } = (await connector(queryPageById, { + id: slug, + })) as WordPressPostProps; if (!page) { - const { post } = await connector(queryPostById, { id: slug }); + const { post } = (await connector(queryPostById, { + id: slug, + })) as WordPressPostProps; if (post) { entity = post; } else { diff --git a/app/wordpress/page.tsx b/app/wordpress/page.tsx index 45168fb..f55ff15 100644 --- a/app/wordpress/page.tsx +++ b/app/wordpress/page.tsx @@ -19,10 +19,13 @@ import Blocks from "@/components/gutenberg/Blocks/Blocks"; * Import type definitions */ import { GutenbergGlobalBlockProps } from "@/types/gutenberg"; +import { WordPressPostProps } from "@/types/wordpress/posts"; export default async function Page() { // @TODO: Looking at the console, it appears this component is getting called twice. Likely for a good reason, but would like to find out why. - const { page } = await connector(queryPageById, { id: "/" }); + const { page } = (await connector(queryPageById, { + id: "/", + })) as WordPressPostProps; if (!page) { // Not found. notFound(); diff --git a/functions/jsonToCssVariables.ts b/functions/jsonToCssVariables.ts index 0c5255e..b41e32e 100644 --- a/functions/jsonToCssVariables.ts +++ b/functions/jsonToCssVariables.ts @@ -1,4 +1,9 @@ -export function convertJsonToCssVariables(json, prefix: string) { +export function convertJsonToCssVariables( + json: { + [key: string]: string; + }, + prefix: string +) { let cssVars = ":root {\n"; for (const key in json) { diff --git a/functions/wordpress/menus/formatNavigationMenu.ts b/functions/wordpress/menus/formatNavigationMenu.ts index b835e70..f484126 100644 --- a/functions/wordpress/menus/formatNavigationMenu.ts +++ b/functions/wordpress/menus/formatNavigationMenu.ts @@ -1,10 +1,12 @@ /** * Import type definitions */ -import { MenuItemProps } from "@/types/wordpress/menus"; +import { WordPressMenuItemProps } from "@/types/wordpress/menus"; -export default function formatNavigationMenu(menuItems: MenuItemProps[]): {} { - return menuItems?.map((item: MenuItemProps) => { +export default function formatNavigationMenu( + menuItems: WordPressMenuItemProps[] +): {} { + return menuItems?.map((item: WordPressMenuItemProps) => { const { children, ...itemProps } = item; return { diff --git a/functions/wordpress/postTypes/getPostTypeStaticPaths.ts b/functions/wordpress/postTypes/getPostTypeStaticPaths.ts index a08baee..08463a7 100644 --- a/functions/wordpress/postTypes/getPostTypeStaticPaths.ts +++ b/functions/wordpress/postTypes/getPostTypeStaticPaths.ts @@ -33,6 +33,7 @@ export default async function getPostTypeStaticPaths( } }`, {} + // @ts-ignore ).then((response) => response?.[pluralName]?.edges ?? []); const paths = posts diff --git a/lib/wordpress/connector.ts b/lib/wordpress/connector.ts index bfa709d..d904b98 100644 --- a/lib/wordpress/connector.ts +++ b/lib/wordpress/connector.ts @@ -3,11 +3,14 @@ import { request, Variables } from "graphql-request"; // Retrieve default SEO and other page data. // @TODO: Improve the type definition for the query & variables parameter -const connector = async (query: string, variables: Variables) => { +const connector = async ( + query: string, + variables: Variables | undefined = undefined +) => { return await request( `${process.env.NEXT_PUBLIC_WORDPRESS_API_URL}/graphql/`, query, - variables + variables || undefined ) .then((data) => data) .catch((error) => { diff --git a/package-lock.json b/package-lock.json index a6fa38d..ea4261e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -61,6 +61,7 @@ "husky": "^8.0.2", "inquirer": "^8.2.5", "leasot": "^13.2.0", + "postcss": "^8.4.13", "sass": "^1.56.1", "stylelint": "^14.16.0", "stylelint-config-standard-scss": "^6.1.0", @@ -5928,6 +5929,23 @@ "node": ">=8" } }, + "node_modules/@storybook/builder-webpack4/node_modules/postcss": { + "version": "7.0.39", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-7.0.39.tgz", + "integrity": "sha512-yioayjNbHn6z1/Bywyb2Y4s3yvDAeXGOyxqD+LnVOinq6Mdmd++SW2wUNVzavyyHxd6+DxzWGIuosg6P1Rj8uA==", + "dev": true, + "dependencies": { + "picocolors": "^0.2.1", + "source-map": "^0.6.1" + }, + "engines": { + "node": ">=6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + } + }, "node_modules/@storybook/builder-webpack4/node_modules/postcss-modules-extract-imports": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/postcss-modules-extract-imports/-/postcss-modules-extract-imports-2.0.0.tgz", @@ -9347,6 +9365,23 @@ "node": ">=8" } }, + "node_modules/@storybook/manager-webpack4/node_modules/postcss": { + "version": "7.0.39", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-7.0.39.tgz", + "integrity": "sha512-yioayjNbHn6z1/Bywyb2Y4s3yvDAeXGOyxqD+LnVOinq6Mdmd++SW2wUNVzavyyHxd6+DxzWGIuosg6P1Rj8uA==", + "dev": true, + "dependencies": { + "picocolors": "^0.2.1", + "source-map": "^0.6.1" + }, + "engines": { + "node": ">=6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + } + }, "node_modules/@storybook/manager-webpack4/node_modules/postcss-modules-extract-imports": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/postcss-modules-extract-imports/-/postcss-modules-extract-imports-2.0.0.tgz", @@ -14853,6 +14888,23 @@ "url": "https://tidelift.com/funding/github/npm/autoprefixer" } }, + "node_modules/autoprefixer/node_modules/postcss": { + "version": "7.0.39", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-7.0.39.tgz", + "integrity": "sha512-yioayjNbHn6z1/Bywyb2Y4s3yvDAeXGOyxqD+LnVOinq6Mdmd++SW2wUNVzavyyHxd6+DxzWGIuosg6P1Rj8uA==", + "dev": true, + "dependencies": { + "picocolors": "^0.2.1", + "source-map": "^0.6.1" + }, + "engines": { + "node": ">=6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + } + }, "node_modules/autosize": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/autosize/-/autosize-4.0.4.tgz", @@ -17535,36 +17587,6 @@ "node": ">=10" } }, - "node_modules/css-loader/node_modules/picocolors": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", - "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==", - "dev": true - }, - "node_modules/css-loader/node_modules/postcss": { - "version": "8.4.21", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.21.tgz", - "integrity": "sha512-tP7u/Sn/dVxK2NnruI4H9BG+x+Wxz6oeZ1cJ8P6G/PZY0IKk4k/63TDsQf2kQq3+qoJeLm2kIBUNlZe3zgb4Zg==", - "dev": true, - "funding": [ - { - "type": "opencollective", - "url": "https://opencollective.com/postcss/" - }, - { - "type": "tidelift", - "url": "https://tidelift.com/funding/github/npm/postcss" - } - ], - "dependencies": { - "nanoid": "^3.3.4", - "picocolors": "^1.0.0", - "source-map-js": "^1.0.2" - }, - "engines": { - "node": "^10 || ^12 || >=14" - } - }, "node_modules/css-loader/node_modules/semver": { "version": "7.4.0", "resolved": "https://registry.npmjs.org/semver/-/semver-7.4.0.tgz", @@ -25988,6 +26010,38 @@ } }, "node_modules/postcss": { + "version": "8.4.21", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.21.tgz", + "integrity": "sha512-tP7u/Sn/dVxK2NnruI4H9BG+x+Wxz6oeZ1cJ8P6G/PZY0IKk4k/63TDsQf2kQq3+qoJeLm2kIBUNlZe3zgb4Zg==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + } + ], + "dependencies": { + "nanoid": "^3.3.4", + "picocolors": "^1.0.0", + "source-map-js": "^1.0.2" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, + "node_modules/postcss-flexbugs-fixes": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/postcss-flexbugs-fixes/-/postcss-flexbugs-fixes-4.2.1.tgz", + "integrity": "sha512-9SiofaZ9CWpQWxOwRh1b/r85KD5y7GgvsNt1056k6OYLvWUun0czCvogfJgylC22uJTwW1KzY3Gz65NZRlvoiQ==", + "dev": true, + "dependencies": { + "postcss": "^7.0.26" + } + }, + "node_modules/postcss-flexbugs-fixes/node_modules/postcss": { "version": "7.0.39", "resolved": "https://registry.npmjs.org/postcss/-/postcss-7.0.39.tgz", "integrity": "sha512-yioayjNbHn6z1/Bywyb2Y4s3yvDAeXGOyxqD+LnVOinq6Mdmd++SW2wUNVzavyyHxd6+DxzWGIuosg6P1Rj8uA==", @@ -26004,15 +26058,6 @@ "url": "https://opencollective.com/postcss/" } }, - "node_modules/postcss-flexbugs-fixes": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/postcss-flexbugs-fixes/-/postcss-flexbugs-fixes-4.2.1.tgz", - "integrity": "sha512-9SiofaZ9CWpQWxOwRh1b/r85KD5y7GgvsNt1056k6OYLvWUun0czCvogfJgylC22uJTwW1KzY3Gz65NZRlvoiQ==", - "dev": true, - "dependencies": { - "postcss": "^7.0.26" - } - }, "node_modules/postcss-loader": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/postcss-loader/-/postcss-loader-4.3.0.tgz", @@ -26217,6 +26262,11 @@ "resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz", "integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==" }, + "node_modules/postcss/node_modules/picocolors": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", + "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==" + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -28298,34 +28348,6 @@ "node": ">=12" } }, - "node_modules/resolve-url-loader/node_modules/picocolors": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", - "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==" - }, - "node_modules/resolve-url-loader/node_modules/postcss": { - "version": "8.4.21", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.21.tgz", - "integrity": "sha512-tP7u/Sn/dVxK2NnruI4H9BG+x+Wxz6oeZ1cJ8P6G/PZY0IKk4k/63TDsQf2kQq3+qoJeLm2kIBUNlZe3zgb4Zg==", - "funding": [ - { - "type": "opencollective", - "url": "https://opencollective.com/postcss/" - }, - { - "type": "tidelift", - "url": "https://tidelift.com/funding/github/npm/postcss" - } - ], - "dependencies": { - "nanoid": "^3.3.4", - "picocolors": "^1.0.0", - "source-map-js": "^1.0.2" - }, - "engines": { - "node": "^10 || ^12 || >=14" - } - }, "node_modules/restore-cursor": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-3.1.0.tgz", @@ -30575,34 +30597,6 @@ "stylelint": "^14.0.0" } }, - "node_modules/stylelint-order/node_modules/picocolors": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", - "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==" - }, - "node_modules/stylelint-order/node_modules/postcss": { - "version": "8.4.21", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.21.tgz", - "integrity": "sha512-tP7u/Sn/dVxK2NnruI4H9BG+x+Wxz6oeZ1cJ8P6G/PZY0IKk4k/63TDsQf2kQq3+qoJeLm2kIBUNlZe3zgb4Zg==", - "funding": [ - { - "type": "opencollective", - "url": "https://opencollective.com/postcss/" - }, - { - "type": "tidelift", - "url": "https://tidelift.com/funding/github/npm/postcss" - } - ], - "dependencies": { - "nanoid": "^3.3.4", - "picocolors": "^1.0.0", - "source-map-js": "^1.0.2" - }, - "engines": { - "node": "^10 || ^12 || >=14" - } - }, "node_modules/stylelint-scss": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/stylelint-scss/-/stylelint-scss-4.6.0.tgz", @@ -30791,30 +30785,6 @@ "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==", "dev": true }, - "node_modules/stylelint/node_modules/postcss": { - "version": "8.4.21", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.21.tgz", - "integrity": "sha512-tP7u/Sn/dVxK2NnruI4H9BG+x+Wxz6oeZ1cJ8P6G/PZY0IKk4k/63TDsQf2kQq3+qoJeLm2kIBUNlZe3zgb4Zg==", - "dev": true, - "funding": [ - { - "type": "opencollective", - "url": "https://opencollective.com/postcss/" - }, - { - "type": "tidelift", - "url": "https://tidelift.com/funding/github/npm/postcss" - } - ], - "dependencies": { - "nanoid": "^3.3.4", - "picocolors": "^1.0.0", - "source-map-js": "^1.0.2" - }, - "engines": { - "node": "^10 || ^12 || >=14" - } - }, "node_modules/stylelint/node_modules/type-fest": { "version": "0.18.1", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.18.1.tgz", diff --git a/package.json b/package.json index 0c47175..397ec72 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,6 @@ "todo": "leasot '**/*.tsx' '**/*.js' '**/*.scss' '**/*.ts' --ignore '**/node_modules' '**/schema.generated.ts'", "commit": "git-cz" }, - "engines": { - "npm": ">=8.11.0", - "node": ">=16.0.0 <17.0.0" - }, "config": { "commitizen": { "path": "@commitlint/cz-commitlint" @@ -80,6 +76,7 @@ "stylelint-config-standard-scss": "^6.1.0", "stylelint-order": "^5.0.0", "stylelint-webpack-plugin": "^3.3.0", - "webpack": "^5.75.0" + "webpack": "^5.75.0", + "postcss": "^8.4.13" } } diff --git a/types/wordpress/menus.d.ts b/types/wordpress/menus.d.ts index 14bed7d..5f5cbd1 100644 --- a/types/wordpress/menus.d.ts +++ b/types/wordpress/menus.d.ts @@ -1,4 +1,4 @@ -export interface MenuItemProps { +export interface WordPressMenuItemProps { __typename: "MenuItem"; id: string; parentId?: string; diff --git a/types/wordpress/posts.d.ts b/types/wordpress/posts.d.ts new file mode 100644 index 0000000..fbafda0 --- /dev/null +++ b/types/wordpress/posts.d.ts @@ -0,0 +1,8 @@ +export interface WordPressPostProps { + page?: { + blocksJSON: string; + }; + post?: { + blocksJSON: string; + }; +}