From f43bcec080e74cf42a2c7d3fa016e5c92e751cd9 Mon Sep 17 00:00:00 2001 From: Jesus Vasquez Date: Sun, 3 Mar 2024 22:17:36 -0500 Subject: [PATCH 01/11] cleanup --- components/Form/data.tsx | 7 +++++ components/Form/formSchemas.ts | 30 ++++++++++++++++++++ components/Form/index.tsx | 50 +++------------------------------- components/Form/types.ts | 8 ++++++ 4 files changed, 49 insertions(+), 46 deletions(-) create mode 100644 components/Form/formSchemas.ts diff --git a/components/Form/data.tsx b/components/Form/data.tsx index e69de29..2a1ab07 100644 --- a/components/Form/data.tsx +++ b/components/Form/data.tsx @@ -0,0 +1,7 @@ +export const data = { + importNames: ["Import ABC", "Import DEF", "Import GHI"], + splitScheduleOptions: ["Yes", "No"], + clientOptions: ["Single", "Multiple"], + testingCenterOptions: ["testing center 1", "testing center 2", "testing center 3", "testing center 4"], + clientsOptions: ["client 1", "client 2", "client 3"], +}; \ No newline at end of file diff --git a/components/Form/formSchemas.ts b/components/Form/formSchemas.ts new file mode 100644 index 0000000..e2070e6 --- /dev/null +++ b/components/Form/formSchemas.ts @@ -0,0 +1,30 @@ +import { FormValues } from "./types"; +import * as Yup from "yup"; + +export const initialValues: FormValues = { + importName: '', + manifestFile: null, + splitSchedule: '', + client: '', + testingCenter: '', + toleranceWindow: false, +}; + +export const validationSchema = Yup.object({ + importName: Yup.string() + .required('Import name is required') + .oneOf(["Import ABC", "Import DEF", "Import GHI"], "Invalid Import Name"), + manifestFile: Yup.mixed() + .required('A file is required') + .nullable(), // Allows for null values + splitSchedule: Yup.string() + .required('This field is required') + .oneOf(["Yes", "No"], "Invalid Option"), + client: Yup.string() + .required('Client selection is required') + .oneOf(["Single", "Multiple"], "Invalid Client Type"), + testingCenter: Yup.string() + .required('Testing center selection is required'), // Assuming a selection is required + toleranceWindow: Yup.boolean() + .required('Tolerance window selection is required'), // Assuming this is a boolean represented by a toggle +}); \ No newline at end of file diff --git a/components/Form/index.tsx b/components/Form/index.tsx index 366b8db..f789491 100644 --- a/components/Form/index.tsx +++ b/components/Form/index.tsx @@ -4,7 +4,7 @@ import React, { useState } from "react"; //Dependencies import { Formik, Form } from "formik"; -import * as Yup from "yup"; + import axios from "axios"; //Input fields @@ -15,51 +15,9 @@ import ToggleField from "./ToggleField"; import StatusField from "./StatusField"; import ClientField from "./ClientField"; -interface FormValues { - importName: string; - manifestFile: File | null; - splitSchedule: string; - client: string; - testingCenter: string; - toleranceWindow: boolean; -} - -const initialValues: FormValues = { - importName: '', - manifestFile: null, - splitSchedule: '', - client: '', - testingCenter: '', - toleranceWindow: false, -}; - -const validationSchema = Yup.object({ - importName: Yup.string() - .required('Import name is required') - .oneOf(["Import ABC", "Import DEF", "Import GHI"], "Invalid Import Name"), - manifestFile: Yup.mixed() - .required('A file is required') - .nullable(), // Allows for null values, adjust based on your logic for file handling - splitSchedule: Yup.string() - .required('This field is required') - .oneOf(["Yes", "No"], "Invalid Option"), - client: Yup.string() - .required('Client selection is required') - .oneOf(["Single", "Multiple"], "Invalid Client Type"), - testingCenter: Yup.string() - .required('Testing center selection is required'), // Assuming a selection is required - toleranceWindow: Yup.boolean() - .required('Tolerance window selection is required'), // Assuming this is a boolean represented by a toggle -}); - - -const data = { - importNames: ["Import ABC", "Import DEF", "Import GHI"], - splitScheduleOptions: ["Yes", "No"], - clientOptions: ["Single", "Multiple"], - testingCenterOptions: ["testing center 1", "testing center 2", "testing center 3", "testing center 4"], - clientsOptions: ["client 1", "client 2", "client 3"], -}; +import { FormValues } from "./types"; +import { data } from "./data"; +import { initialValues, validationSchema } from "./formSchemas"; const FormComponent: React.FC = () => { const [formSubmitted, setFormSubmitted] = useState(false); diff --git a/components/Form/types.ts b/components/Form/types.ts index e69de29..3793f42 100644 --- a/components/Form/types.ts +++ b/components/Form/types.ts @@ -0,0 +1,8 @@ +export interface FormValues { + importName: string; + manifestFile: File | null; + splitSchedule: string; + client: string; + testingCenter: string; + toleranceWindow: boolean; +} \ No newline at end of file From 4adcee4af774f6048affd580940ed08b96a56d20 Mon Sep 17 00:00:00 2001 From: Jesus Vasquez Date: Sun, 3 Mar 2024 22:34:43 -0500 Subject: [PATCH 02/11] prettier, lint cleanup --- app/page.tsx | 4 +- components/Form/ClientField.tsx | 31 +++-- components/Form/FileInput.tsx | 66 +++++------ components/Form/RadioGroup.tsx | 9 +- components/Form/ToggleField.tsx | 28 ++--- components/Form/data.tsx | 12 +- components/Form/formSchemas.ts | 44 +++---- components/Form/index.tsx | 199 +++++++++++++------------------- components/Form/types.ts | 14 +-- 9 files changed, 176 insertions(+), 231 deletions(-) diff --git a/app/page.tsx b/app/page.tsx index 3726b4b..3f0fcf6 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,6 +1,6 @@ -import { Metadata } from "next" -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" import { faXmark } from "@fortawesome/free-solid-svg-icons" +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" +import { Metadata } from "next" import Form from "components/Form" export const metadata: Metadata = { diff --git a/components/Form/ClientField.tsx b/components/Form/ClientField.tsx index da2bc68..02ff447 100644 --- a/components/Form/ClientField.tsx +++ b/components/Form/ClientField.tsx @@ -1,13 +1,13 @@ +import { faClock } from "@fortawesome/free-regular-svg-icons" +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" import React from "react" import SelectInput from "./SelectInput" import { Utils } from "./Utils" -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" -import { faClock } from "@fortawesome/free-regular-svg-icons" // Define a type for your props to improve type-checking type ClientFieldProps = { - testingCenters: string[] - clients: string[] + testingCenters: string[] + clients: string[] } // Destructure the props in the function parameter @@ -15,20 +15,19 @@ const ClientField: React.FC = ({ testingCenters, clients }) => return (
{testingCenters.map((testingCenter) => ( -
+
{testingCenter} -
+
- - {clients.map((option: string) => ( - - ))} - - -
- + + {clients.map((option: string) => ( + + ))} + + +
))}
diff --git a/components/Form/FileInput.tsx b/components/Form/FileInput.tsx index 25b7a3b..daed5b0 100644 --- a/components/Form/FileInput.tsx +++ b/components/Form/FileInput.tsx @@ -1,44 +1,43 @@ -import { useField, useFormikContext } from "formik"; -import React, { useRef } from "react"; -import ErrorMessage from "./ErrorMessage"; -import RequiredAsterisk from "./RequiredAsterisk"; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { faFile } from "@fortawesome/free-solid-svg-icons"; - +import { faFile } from "@fortawesome/free-solid-svg-icons" +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" +import { useField, useFormikContext } from "formik" +import React, { useRef } from "react" +import ErrorMessage from "./ErrorMessage" +import RequiredAsterisk from "./RequiredAsterisk" interface FileInputProps { - label: string; - required?: boolean; - name:string; + label: string + required?: boolean + name: string } -const FileInput: React.FC = ({ label, ...props }) => { - const { required } = props; - const [field, meta] = useField(props); - const { setFieldValue } = useFormikContext(); - const fileInputRef = useRef(null); +const FileInput: React.FC = ({ label, ...props }) => { + const { required } = props + const [field, meta] = useField(props) + const { setFieldValue } = useFormikContext() + const fileInputRef = useRef(null) const handleChange = (event: React.ChangeEvent) => { - const { files } = event.target; - const file = files ? files[0] : null; - setFieldValue(props.name, file); // Directly use setFieldValue to update Formik's state - }; + const { files } = event.target + const file = files ? files[0] : null + setFieldValue(props.name, file) // Directly use setFieldValue to update Formik's state + } const handleClick = () => { if (fileInputRef.current) { - fileInputRef.current.click(); + fileInputRef.current.click() } - }; + } const handleDrop = (event: React.DragEvent) => { - event.preventDefault(); - event.stopPropagation(); - const files = event.dataTransfer.files; + event.preventDefault() + event.stopPropagation() + const files = event.dataTransfer.files if (files && files.length > 0) { - const file = files[0]; - setFieldValue(props.name, file); + const file = files[0] + setFieldValue(props.name, file) } - }; + } return (
@@ -53,15 +52,10 @@ const FileInput: React.FC = ({ label, ...props }) => {
- + - ); -}; + ) +} -export default FileInput; +export default FileInput diff --git a/components/Form/RadioGroup.tsx b/components/Form/RadioGroup.tsx index 9886d69..a356049 100644 --- a/components/Form/RadioGroup.tsx +++ b/components/Form/RadioGroup.tsx @@ -1,8 +1,8 @@ +import * as RadioGroup from "@radix-ui/react-radio-group" import { useField } from "formik" import React from "react" import ErrorMessage from "./ErrorMessage" import RequiredAsterisk from "./RequiredAsterisk" -import * as RadioGroup from "@radix-ui/react-radio-group" const RadioGroupField = ({ name, @@ -28,12 +28,7 @@ const RadioGroupField = ({ {label} - + {options.map((option) => (
) => { - const { required, ...restProps } = props; - const [field, meta] = useField({ ...(restProps as { name: string }), type: "checkbox" }); - const [checked, setChecked] = useState(false); + const { required, ...restProps } = props + const [field, meta] = useField({ ...(restProps as { name: string }), type: "checkbox" }) + const [checked, setChecked] = useState(false) return (
@@ -24,15 +24,15 @@ const ToggleField = ({ className="relative h-[25px] w-[42px] cursor-default rounded-full bg-black shadow-[0_2px_10px] outline-none focus:shadow-[0_0_0_2px] focus:shadow-black" checked={checked} onCheckedChange={(isChecked) => { - setChecked(isChecked); - field.onChange({ target: { name: field.name, value: isChecked } }); + setChecked(isChecked) + field.onChange({ target: { name: field.name, value: isChecked } }) }} >
- ); -}; + ) +} -export default ToggleField; +export default ToggleField diff --git a/components/Form/data.tsx b/components/Form/data.tsx index 2a1ab07..e4d295b 100644 --- a/components/Form/data.tsx +++ b/components/Form/data.tsx @@ -1,7 +1,7 @@ export const data = { - importNames: ["Import ABC", "Import DEF", "Import GHI"], - splitScheduleOptions: ["Yes", "No"], - clientOptions: ["Single", "Multiple"], - testingCenterOptions: ["testing center 1", "testing center 2", "testing center 3", "testing center 4"], - clientsOptions: ["client 1", "client 2", "client 3"], -}; \ No newline at end of file + importNames: ["Import ABC", "Import DEF", "Import GHI"], + splitScheduleOptions: ["Yes", "No"], + clientOptions: ["Single", "Multiple"], + testingCenterOptions: ["testing center 1", "testing center 2", "testing center 3", "testing center 4"], + clientsOptions: ["client 1", "client 2", "client 3"], +} diff --git a/components/Form/formSchemas.ts b/components/Form/formSchemas.ts index e2070e6..38ac1d7 100644 --- a/components/Form/formSchemas.ts +++ b/components/Form/formSchemas.ts @@ -1,30 +1,22 @@ -import { FormValues } from "./types"; -import * as Yup from "yup"; +import * as Yup from "yup" +import { FormValues } from "./types" export const initialValues: FormValues = { - importName: '', - manifestFile: null, - splitSchedule: '', - client: '', - testingCenter: '', - toleranceWindow: false, -}; + importName: "", + manifestFile: null, + splitSchedule: "", + client: "", + testingCenter: "", + toleranceWindow: false, +} export const validationSchema = Yup.object({ - importName: Yup.string() - .required('Import name is required') - .oneOf(["Import ABC", "Import DEF", "Import GHI"], "Invalid Import Name"), - manifestFile: Yup.mixed() - .required('A file is required') - .nullable(), // Allows for null values - splitSchedule: Yup.string() - .required('This field is required') - .oneOf(["Yes", "No"], "Invalid Option"), - client: Yup.string() - .required('Client selection is required') - .oneOf(["Single", "Multiple"], "Invalid Client Type"), - testingCenter: Yup.string() - .required('Testing center selection is required'), // Assuming a selection is required - toleranceWindow: Yup.boolean() - .required('Tolerance window selection is required'), // Assuming this is a boolean represented by a toggle -}); \ No newline at end of file + importName: Yup.string() + .required("Import name is required") + .oneOf(["Import ABC", "Import DEF", "Import GHI"], "Invalid Import Name"), + manifestFile: Yup.mixed().required("A file is required").nullable(), // Allows for null values + splitSchedule: Yup.string().required("This field is required").oneOf(["Yes", "No"], "Invalid Option"), + client: Yup.string().required("Client selection is required").oneOf(["Single", "Multiple"], "Invalid Client Type"), + testingCenter: Yup.string().required("Testing center selection is required"), // Assuming a selection is required + toleranceWindow: Yup.boolean().required("Tolerance window selection is required"), // Assuming this is a boolean represented by a toggle +}) diff --git a/components/Form/index.tsx b/components/Form/index.tsx index f789491..561cabb 100644 --- a/components/Form/index.tsx +++ b/components/Form/index.tsx @@ -1,130 +1,95 @@ "use client" -import React, { useState } from "react"; +import axios from "axios" +import { Form, Formik } from "formik" +import React, { useState } from "react" //Dependencies -import { Formik, Form } from "formik"; - -import axios from "axios"; //Input fields -import SelectInput from "./SelectInput"; -import RadioGroup from "./RadioGroup"; -import FileInput from "./FileInput"; -import ToggleField from "./ToggleField"; -import StatusField from "./StatusField"; -import ClientField from "./ClientField"; +import ClientField from "./ClientField" +import { data } from "./data" +import FileInput from "./FileInput" +import { initialValues, validationSchema } from "./formSchemas" +import RadioGroup from "./RadioGroup" +import SelectInput from "./SelectInput" +import StatusField from "./StatusField" +import ToggleField from "./ToggleField" -import { FormValues } from "./types"; -import { data } from "./data"; -import { initialValues, validationSchema } from "./formSchemas"; +import { FormValues } from "./types" const FormComponent: React.FC = () => { - const [formSubmitted, setFormSubmitted] = useState(false); + const [formSubmitted, setFormSubmitted] = useState(false) - const submitForm = (values: FormValues) => { - return axios.post( - `/api/submitForm`, - { - submissionData: values, - }, - { - // options - headers: { - "Content-Type": "application/json" - } - } - ); - }; - - return ( - { - try { - console.log(values); - await submitForm(values); - setFormSubmitted(true); - } catch (error) { - console.error("Error submitting form:", error); - } finally { - setSubmitting(false); - } - }} - > - {formik => ( -
-
-
- - - {data.importNames.map(option => ( - - ))} - - - - Tolerance Window: -
-
- - - - -
-
- -
- )} -
- + const submitForm = (values: FormValues) => { + return axios.post( + `/api/submitForm`, + { + submissionData: values, + }, + { + // options + headers: { + "Content-Type": "application/json", + }, + } ) + } + + return ( + { + try { + console.log(values) + await submitForm(values) + setFormSubmitted(true) + } catch (error) { + console.error("Error submitting form:", error) + } finally { + setSubmitting(false) + } + }} + > + {(formik) => ( +
+
+
+ + + {data.importNames.map((option) => ( + + ))} + + + + + Tolerance Window: + +
+
+ + + + +
+
+ +
+ )} +
+ ) } -export default FormComponent; - +export default FormComponent diff --git a/components/Form/types.ts b/components/Form/types.ts index 3793f42..fea6431 100644 --- a/components/Form/types.ts +++ b/components/Form/types.ts @@ -1,8 +1,8 @@ export interface FormValues { - importName: string; - manifestFile: File | null; - splitSchedule: string; - client: string; - testingCenter: string; - toleranceWindow: boolean; -} \ No newline at end of file + importName: string + manifestFile: File | null + splitSchedule: string + client: string + testingCenter: string + toleranceWindow: boolean +} From 9f250364e4deaefb39f34322bdcb9da226acdfe2 Mon Sep 17 00:00:00 2001 From: Jesus Vasquez Date: Sun, 3 Mar 2024 23:32:46 -0500 Subject: [PATCH 03/11] work in progress --- components/Form/FileInput.tsx | 10 ++-- components/Form/formSchemas.ts | 10 +++- components/Form/index.tsx | 90 ++++++++++++++++++++-------------- components/Form/types.ts | 16 +++--- 4 files changed, 76 insertions(+), 50 deletions(-) diff --git a/components/Form/FileInput.tsx b/components/Form/FileInput.tsx index daed5b0..7a79146 100644 --- a/components/Form/FileInput.tsx +++ b/components/Form/FileInput.tsx @@ -45,12 +45,12 @@ const FileInput: React.FC = ({ label, ...props }) => { {label} -
e.preventDefault()}> -
- -

Drag & Drop Here or Browse

+
e.preventDefault()}> +
+ +

Drag & Drop Here or Browse

- +
diff --git a/components/Form/formSchemas.ts b/components/Form/formSchemas.ts index 38ac1d7..367c036 100644 --- a/components/Form/formSchemas.ts +++ b/components/Form/formSchemas.ts @@ -6,7 +6,10 @@ export const initialValues: FormValues = { manifestFile: null, splitSchedule: "", client: "", - testingCenter: "", + testingCenter1: "", + testingCenter2: "", + testingCenter3: "", + testingCenter4: "", toleranceWindow: false, } @@ -17,6 +20,9 @@ export const validationSchema = Yup.object({ manifestFile: Yup.mixed().required("A file is required").nullable(), // Allows for null values splitSchedule: Yup.string().required("This field is required").oneOf(["Yes", "No"], "Invalid Option"), client: Yup.string().required("Client selection is required").oneOf(["Single", "Multiple"], "Invalid Client Type"), - testingCenter: Yup.string().required("Testing center selection is required"), // Assuming a selection is required + testingCenter1: Yup.string().required("Testing center selection is required"), // Assuming a selection is required + testingCenter2: Yup.string().required("Testing center selection is required"), // Assuming a selection is required + testingCenter3: Yup.string().required("Testing center selection is required"), // Assuming a selection is required + testingCenter4: Yup.string().required("Testing center selection is required"), // Assuming a selection is required toleranceWindow: Yup.boolean().required("Tolerance window selection is required"), // Assuming this is a boolean represented by a toggle }) diff --git a/components/Form/index.tsx b/components/Form/index.tsx index 561cabb..e4b5397 100644 --- a/components/Form/index.tsx +++ b/components/Form/index.tsx @@ -37,13 +37,14 @@ const FormComponent: React.FC = () => { } return ( + <> { + console.log("Form values:", values); // Log form values on submit try { - console.log(values) - await submitForm(values) + //await submitForm(values) setFormSubmitted(true) } catch (error) { console.error("Error submitting form:", error) @@ -52,43 +53,58 @@ const FormComponent: React.FC = () => { } }} > - {(formik) => ( -
-
-
- - - {data.importNames.map((option) => ( - - ))} - - - - - Tolerance Window: - + {(formik) => { + console.log("Form errors:", formik.errors); // Log form errors on every render + console.log("Form values:", formik.values); // Log current form values on every render + + return ( + +
+
+ + + {data.importNames.map((option) => ( + + ))} + + {/* */} + + + Tolerance Window: + +
+
+ + + + +
-
- - - - -
-
- - - )} + + + ) + } + + } + {formSubmitted &&
Success
} + + ) } diff --git a/components/Form/types.ts b/components/Form/types.ts index fea6431..e7d0660 100644 --- a/components/Form/types.ts +++ b/components/Form/types.ts @@ -1,8 +1,12 @@ export interface FormValues { - importName: string - manifestFile: File | null - splitSchedule: string - client: string - testingCenter: string - toleranceWindow: boolean + importName: string; + manifestFile: File | null; + splitSchedule: string; + client: string; + testingCenter1: string; + testingCenter2: string; + testingCenter3: string; + testingCenter4: string; + toleranceWindow: boolean; } + From 59a7bcc224bebce8f9c91664570484296ffd00a7 Mon Sep 17 00:00:00 2001 From: Jesus Vasquez Date: Mon, 4 Mar 2024 07:53:06 -0500 Subject: [PATCH 04/11] file upload progress --- components/Form/FileInput.tsx | 118 +++++++++++++++++++++++++--------- components/Form/index.tsx | 2 +- 2 files changed, 89 insertions(+), 31 deletions(-) diff --git a/components/Form/FileInput.tsx b/components/Form/FileInput.tsx index 7a79146..89eeba3 100644 --- a/components/Form/FileInput.tsx +++ b/components/Form/FileInput.tsx @@ -1,43 +1,81 @@ -import { faFile } from "@fortawesome/free-solid-svg-icons" -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" -import { useField, useFormikContext } from "formik" -import React, { useRef } from "react" -import ErrorMessage from "./ErrorMessage" -import RequiredAsterisk from "./RequiredAsterisk" +import { faFile } from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { useField, useFormikContext } from "formik"; +import React, { useRef, useState } from "react"; +import ErrorMessage from "./ErrorMessage"; +import RequiredAsterisk from "./RequiredAsterisk"; interface FileInputProps { - label: string - required?: boolean - name: string + label: string; + required?: boolean; + name: string; } const FileInput: React.FC = ({ label, ...props }) => { - const { required } = props - const [field, meta] = useField(props) - const { setFieldValue } = useFormikContext() - const fileInputRef = useRef(null) + const { required } = props; + const [field, meta] = useField(props); + const { setFieldValue } = useFormikContext(); + const fileInputRef = useRef(null); + const [dragging, setDragging] = useState(false); // State to handle drag styling + const [fileInfo, setFileInfo] = useState<{ name: string; size: number } | null>(null); // State to store file info + const [uploadProgress, setUploadProgress] = useState(0); + + const simulateUpload = () => { + let progress = 0; + const interval = setInterval(() => { + progress += 10; + setUploadProgress(progress); + if (progress >= 100) { + clearInterval(interval); + } + }, 20); // Adjust time interval to control speed of the animation + }; const handleChange = (event: React.ChangeEvent) => { - const { files } = event.target - const file = files ? files[0] : null - setFieldValue(props.name, file) // Directly use setFieldValue to update Formik's state - } + const { files } = event.target; + const file = files ? files[0] : null; + setFieldValue(props.name, file); // Update Formik's state + if (file) { + setFileInfo({ name: file.name, size: file.size }); + setUploadProgress(0); // Reset progress + simulateUpload(); // Simulate upload process + } + }; const handleClick = () => { if (fileInputRef.current) { - fileInputRef.current.click() + fileInputRef.current.click(); } - } + }; const handleDrop = (event: React.DragEvent) => { - event.preventDefault() - event.stopPropagation() - const files = event.dataTransfer.files + event.preventDefault(); + event.stopPropagation(); + setDragging(false); // Reset drag state + const files = event.dataTransfer.files; if (files && files.length > 0) { - const file = files[0] - setFieldValue(props.name, file) + const file = files[0]; + if (file) { + setFileInfo({ name: file.name, size: file.size }); + setFieldValue(props.name, file); + } + setUploadProgress(0); // Reset progress + simulateUpload(); // Simulate upload process } - } +}; + + + const handleDragOver = (event: React.DragEvent) => { + event.preventDefault(); + if (!dragging) { + setDragging(true); + } + }; + + const handleDragLeave = (event: React.DragEvent) => { + event.preventDefault(); + setDragging(false); + }; return (
@@ -45,17 +83,37 @@ const FileInput: React.FC = ({ label, ...props }) => { {label} -
e.preventDefault()}> +
-

Drag & Drop Here or Browse

+

Drag & Drop Here or Browse

+ {fileInfo && ( +
+ +
+
+

{fileInfo.name}

+

{Math.round(fileInfo.size / 1024)} KB

+
+
+
+
+
+
+ )}
- ) -} + ); +}; -export default FileInput +export default FileInput; diff --git a/components/Form/index.tsx b/components/Form/index.tsx index e4b5397..ac41a0a 100644 --- a/components/Form/index.tsx +++ b/components/Form/index.tsx @@ -69,7 +69,7 @@ const FormComponent: React.FC = () => { ))} - {/* */} + Tolerance Window: From fadaa0fe4ad86340d6ecac058ac2188cf569cff5 Mon Sep 17 00:00:00 2001 From: Jesus Vasquez Date: Mon, 4 Mar 2024 20:50:32 -0500 Subject: [PATCH 05/11] styling --- app/page.tsx | 2 +- components/Form/ErrorMessage.tsx | 2 +- components/Form/FileInput.tsx | 24 ++++++++++++---- components/Form/RadioGroup.tsx | 17 +++++++---- components/Form/RequiredAsterisk.tsx | 2 +- components/Form/SelectInput.tsx | 13 ++++++--- components/Form/Separator.tsx | 9 ++++++ components/Form/StatusField.tsx | 8 ++++-- components/Form/ToggleField.tsx | 42 ++++++++++++++++++---------- components/Form/formSchemas.ts | 4 --- components/Form/index.tsx | 19 +++++++------ 11 files changed, 94 insertions(+), 48 deletions(-) create mode 100644 components/Form/Separator.tsx diff --git a/app/page.tsx b/app/page.tsx index 3f0fcf6..a2c83d2 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -17,7 +17,7 @@ export default function Web() {
{/* Title */} -
+

Document Upload

{/* Form layout */} diff --git a/components/Form/ErrorMessage.tsx b/components/Form/ErrorMessage.tsx index 4b3534d..7d36578 100644 --- a/components/Form/ErrorMessage.tsx +++ b/components/Form/ErrorMessage.tsx @@ -2,7 +2,7 @@ import React from "react" const ErrorMessage = ({ touched, error }: { touched: boolean; error?: string }) => { if (touched && error) { - return

{error}

+ return

{error}

} return null } diff --git a/components/Form/FileInput.tsx b/components/Form/FileInput.tsx index 89eeba3..712c27a 100644 --- a/components/Form/FileInput.tsx +++ b/components/Form/FileInput.tsx @@ -4,6 +4,7 @@ import { useField, useFormikContext } from "formik"; import React, { useRef, useState } from "react"; import ErrorMessage from "./ErrorMessage"; import RequiredAsterisk from "./RequiredAsterisk"; +import Separator from "./Separator"; interface FileInputProps { label: string; @@ -78,11 +79,17 @@ const FileInput: React.FC = ({ label, ...props }) => { }; return ( -
- +
+ {/* Title */} +
+ + +
+ + {/* File drop area */}
= ({ label, ...props }) => {
+ + {/* Hidden input */} + + {/* File info */} {fileInfo && ( -
+
@@ -111,6 +122,7 @@ const FileInput: React.FC = ({ label, ...props }) => {
)} +
); diff --git a/components/Form/RadioGroup.tsx b/components/Form/RadioGroup.tsx index a356049..5fecb8c 100644 --- a/components/Form/RadioGroup.tsx +++ b/components/Form/RadioGroup.tsx @@ -3,6 +3,7 @@ import { useField } from "formik" import React from "react" import ErrorMessage from "./ErrorMessage" import RequiredAsterisk from "./RequiredAsterisk" +import Separator from "./Separator" const RadioGroupField = ({ name, @@ -23,11 +24,15 @@ const RadioGroupField = ({ } return ( -
- - +
+
+ + +
+ {options.map((option) => (
@@ -36,7 +41,7 @@ const RadioGroupField = ({ value={option} id={`${name}-${option}`} > - +