Skip to content

Commit

Permalink
build(clean up): code clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarshall511 committed Apr 11, 2023
1 parent afd4af5 commit 2183cdb
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 143 deletions.
18 changes: 9 additions & 9 deletions app/components/gutenberg/gravity-forms/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,36 @@ 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.
* Look at Remix framework and check if we can implement something similar for next forms.
*/
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
Expand All @@ -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);
}
};
Expand Down
9 changes: 7 additions & 2 deletions app/wordpress/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion app/wordpress/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion functions/jsonToCssVariables.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
8 changes: 5 additions & 3 deletions functions/wordpress/menus/formatNavigationMenu.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 1 addition & 0 deletions functions/wordpress/postTypes/getPostTypeStaticPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default async function getPostTypeStaticPaths(
}
}`,
{}
// @ts-ignore
).then((response) => response?.[pluralName]?.edges ?? []);

const paths = posts
Expand Down
7 changes: 5 additions & 2 deletions lib/wordpress/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Loading

1 comment on commit 2183cdb

@vercel
Copy link

@vercel vercel bot commented on 2183cdb Apr 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.