Skip to content

Commit 2183cdb

Browse files
committed
build(clean up): code clean-up
1 parent afd4af5 commit 2183cdb

File tree

11 files changed

+137
-143
lines changed

11 files changed

+137
-143
lines changed

app/components/gutenberg/gravity-forms/Form/Form.tsx

+9-9
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,36 @@ export default function Form(props: { formId: string }) {
3030
// Form success and error message.
3131
const success = () => {
3232
messageApi.open({
33-
type: 'success',
34-
content: 'Your form was successfully submitted',
33+
type: "success",
34+
content: "Your form was successfully submitted",
3535
});
3636
};
3737

3838
const error = () => {
3939
messageApi.open({
40-
type: 'error',
41-
content: 'Something went wrong please try again',
40+
type: "error",
41+
content: "Something went wrong please try again",
4242
});
4343
};
4444

45-
4645
// On form Submit.
4746
// @TODO: Add type for function parameter
4847
const onFinish = async (values: any) => {
49-
setLoading(true)
48+
setLoading(true);
5049
const response = await insertGfFormEntry(formId, values, formData);
5150
/**
5251
* @TODO: Find a way to add support for server side validation error if possible.
5352
* Look at Remix framework and check if we can implement something similar for next forms.
5453
*/
5554
if (response?.errors?.length > 0) {
5655
// Set form error as per the requirement.
57-
error()
56+
error();
5857
} else {
5958
// Navigate user to success page or set a success message as required
60-
success()
59+
success();
6160
form.resetFields();
6261
}
63-
setLoading(false)
62+
setLoading(false);
6463
};
6564

6665
// Form Layout for Fields
@@ -84,6 +83,7 @@ export default function Form(props: { formId: string }) {
8483
const fetchData = async () => {
8584
const response = await getGfFormById(formId);
8685
if (response) {
86+
// @ts-ignore
8787
setFormData(response.gfForm);
8888
}
8989
};

app/wordpress/[...slug]/page.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ import Blocks from "@/components/gutenberg/Blocks/Blocks";
2020
* Import type definitions
2121
*/
2222
import { GutenbergGlobalBlockProps } from "@/types/gutenberg";
23+
import { WordPressPostProps } from "@/types/wordpress/posts";
2324

2425
export default async function Page({ params }: { params: { slug: string } }) {
2526
let entity;
2627
const slug = Array.isArray(params.slug) ? params.slug.join("/") : params.slug;
27-
const { page } = await connector(queryPageById, { id: slug });
28+
const { page } = (await connector(queryPageById, {
29+
id: slug,
30+
})) as WordPressPostProps;
2831
if (!page) {
29-
const { post } = await connector(queryPostById, { id: slug });
32+
const { post } = (await connector(queryPostById, {
33+
id: slug,
34+
})) as WordPressPostProps;
3035
if (post) {
3136
entity = post;
3237
} else {

app/wordpress/page.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ import Blocks from "@/components/gutenberg/Blocks/Blocks";
1919
* Import type definitions
2020
*/
2121
import { GutenbergGlobalBlockProps } from "@/types/gutenberg";
22+
import { WordPressPostProps } from "@/types/wordpress/posts";
2223

2324
export default async function Page() {
2425
// @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.
25-
const { page } = await connector(queryPageById, { id: "/" });
26+
const { page } = (await connector(queryPageById, {
27+
id: "/",
28+
})) as WordPressPostProps;
2629
if (!page) {
2730
// Not found.
2831
notFound();

functions/jsonToCssVariables.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
export function convertJsonToCssVariables(json, prefix: string) {
1+
export function convertJsonToCssVariables(
2+
json: {
3+
[key: string]: string;
4+
},
5+
prefix: string
6+
) {
27
let cssVars = ":root {\n";
38

49
for (const key in json) {

functions/wordpress/menus/formatNavigationMenu.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
/**
22
* Import type definitions
33
*/
4-
import { MenuItemProps } from "@/types/wordpress/menus";
4+
import { WordPressMenuItemProps } from "@/types/wordpress/menus";
55

6-
export default function formatNavigationMenu(menuItems: MenuItemProps[]): {} {
7-
return menuItems?.map((item: MenuItemProps) => {
6+
export default function formatNavigationMenu(
7+
menuItems: WordPressMenuItemProps[]
8+
): {} {
9+
return menuItems?.map((item: WordPressMenuItemProps) => {
810
const { children, ...itemProps } = item;
911

1012
return {

functions/wordpress/postTypes/getPostTypeStaticPaths.ts

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export default async function getPostTypeStaticPaths(
3333
}
3434
}`,
3535
{}
36+
// @ts-ignore
3637
).then((response) => response?.[pluralName]?.edges ?? []);
3738

3839
const paths = posts

lib/wordpress/connector.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import { request, Variables } from "graphql-request";
33

44
// Retrieve default SEO and other page data.
55
// @TODO: Improve the type definition for the query & variables parameter
6-
const connector = async (query: string, variables: Variables) => {
6+
const connector = async (
7+
query: string,
8+
variables: Variables | undefined = undefined
9+
) => {
710
return await request(
811
`${process.env.NEXT_PUBLIC_WORDPRESS_API_URL}/graphql/`,
912
query,
10-
variables
13+
variables || undefined
1114
)
1215
.then((data) => data)
1316
.catch((error) => {

0 commit comments

Comments
 (0)