From 6daae28c395f007ccb77349d9edd5eb423f5d23f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Brenes?= Date: Mon, 30 Sep 2024 20:56:39 -0600 Subject: [PATCH 1/4] fix: validate the goal type input --- .../modules/newfunding/FundingStep.tsx | 65 +++++++++++++------ 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/frontend/gostarkme-web/components/modules/newfunding/FundingStep.tsx b/frontend/gostarkme-web/components/modules/newfunding/FundingStep.tsx index 480cccd..e6cc7bb 100644 --- a/frontend/gostarkme-web/components/modules/newfunding/FundingStep.tsx +++ b/frontend/gostarkme-web/components/modules/newfunding/FundingStep.tsx @@ -1,3 +1,5 @@ +import React, { useState } from 'react'; + interface FundingStepProps { fundingName: string; setFundingName: (name: string) => void; @@ -10,25 +12,48 @@ const FundingStep: React.FC = ({ setFundingName, name, setName, -}) => ( -
- setFundingName(e.target.value)} - className="mt-2 p-2 pl-4 border border-black rounded w-full placeholder:text-base" - required - /> - setName(e.target.value)} - className="mt-4 p-2 pl-4 border border-black rounded w-full placeholder:text-base" - required - /> -
-); +}) => { + const [errors, setErrors] = useState([]); + + const handleGoal = (e: React.ChangeEvent) => { + const newValue = e.target.value; + + if (newValue === '' || !isNaN(Number(newValue))) { + setName(newValue); + setErrors([]); + } else { + setErrors(['The goal has to be of number type']); + } + }; + + return ( +
+ {errors.length > 0 && ( +
+ {errors.map((error, index) => ( +
{error}
+ ))} +
+ )} + + setFundingName(e.target.value)} + className="mt-2 p-2 pl-4 border border-black rounded w-full placeholder:text-base" + required + /> + +
+ ); +}; export default FundingStep; From 65a03118683b001ff5af19bd3eaa238c2c113e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Brenes?= Date: Mon, 30 Sep 2024 20:57:01 -0600 Subject: [PATCH 2/4] fix: change the discord link --- frontend/gostarkme-web/components/ui/Footer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/gostarkme-web/components/ui/Footer.tsx b/frontend/gostarkme-web/components/ui/Footer.tsx index 084efb0..bb647eb 100644 --- a/frontend/gostarkme-web/components/ui/Footer.tsx +++ b/frontend/gostarkme-web/components/ui/Footer.tsx @@ -47,7 +47,7 @@ const Footer = (): React.JSX.Element => { /> - + Date: Mon, 30 Sep 2024 22:30:19 -0600 Subject: [PATCH 3/4] fix: add warning to form labels empty --- .../components/modules/Fund/FundDonate.tsx | 39 ++++++++++++-- .../modules/newfunding/FundingStep.tsx | 54 +++++++++++++------ .../components/modules/newfunding/Stages.tsx | 25 +++++++-- 3 files changed, 93 insertions(+), 25 deletions(-) diff --git a/frontend/gostarkme-web/components/modules/Fund/FundDonate.tsx b/frontend/gostarkme-web/components/modules/Fund/FundDonate.tsx index 22840db..a6c41d3 100644 --- a/frontend/gostarkme-web/components/modules/Fund/FundDonate.tsx +++ b/frontend/gostarkme-web/components/modules/Fund/FundDonate.tsx @@ -1,6 +1,5 @@ "use client"; -import { LinkButton } from "@/components/ui/LinkButton"; import ProgressBar from "@/components/ui/ProgressBar"; import Image, { StaticImageData } from "next/image"; import { useState } from "react"; @@ -10,13 +9,31 @@ interface FundDonateProps { } const FundDonate = ({ icon }: FundDonateProps) => { - const [amount, setAmount] = useState(); + const [amount, setAmount] = useState(""); + const [error, setError] = useState(""); const handleAmountChange = (e: React.ChangeEvent) => { - const value = Number(e.target.value); + const value = e.target.value === "" ? "" : Number(e.target.value); setAmount(value); + setError(""); }; + const handleDonateClick = (e: React.MouseEvent) => { + e.preventDefault(); + if (amount === "") { + setError("This field is required."); + } else if (typeof amount === "number" && amount < 0) { + setError("The amount cannot be negative."); + } else { + console.log("Donating:", amount); + setError(""); + setTimeout(() => { + window.location.href = "/"; + }, 0); + } + }; + + return (
@@ -26,14 +43,26 @@ const FundDonate = ({ icon }: FundDonateProps) => {
- + {error && ( +

{error}

+ )} + ); }; diff --git a/frontend/gostarkme-web/components/modules/newfunding/FundingStep.tsx b/frontend/gostarkme-web/components/modules/newfunding/FundingStep.tsx index e6cc7bb..b46f515 100644 --- a/frontend/gostarkme-web/components/modules/newfunding/FundingStep.tsx +++ b/frontend/gostarkme-web/components/modules/newfunding/FundingStep.tsx @@ -1,10 +1,12 @@ -import React, { useState } from 'react'; +import React from 'react'; interface FundingStepProps { fundingName: string; setFundingName: (name: string) => void; name: string; setName: (name: string) => void; + errors: { fundingName: string; name: string }; // Expecting errors as props + setErrors: React.Dispatch>; // Specify the type for setErrors } const FundingStep: React.FC = ({ @@ -12,36 +14,45 @@ const FundingStep: React.FC = ({ setFundingName, name, setName, + errors, + setErrors, }) => { - const [errors, setErrors] = useState([]); - const handleGoal = (e: React.ChangeEvent) => { const newValue = e.target.value; - if (newValue === '' || !isNaN(Number(newValue))) { + // Check if the input is empty or a valid non-negative number + if (newValue === '' || (Number(newValue) >= 0 && !isNaN(Number(newValue)))) { setName(newValue); - setErrors([]); + setErrors((prev) => ({ ...prev, name: '' })); } else { - setErrors(['The goal has to be of number type']); + setErrors((prev) => ({ ...prev, name: 'The goal must be a non-negative number.' })); + } + }; + + const handleFundingNameChange = (e: React.ChangeEvent) => { + const newValue = e.target.value; + setFundingName(newValue); + + // Validate funding name to allow only alphabetic characters + const isValidName = /^[A-Za-z\s]*$/.test(newValue); // Allow letters and spaces only + + if (!newValue) { + setErrors((prev) => ({ ...prev, fundingName: 'Funding name is required.' })); + } else if (!isValidName) { + setErrors((prev) => ({ ...prev, fundingName: 'Funding name cannot contain numbers or symbols.' })); + } else { + setErrors((prev) => ({ ...prev, fundingName: '' })); } }; return (
- {errors.length > 0 && ( -
- {errors.map((error, index) => ( -
{error}
- ))} -
- )} - setFundingName(e.target.value)} - className="mt-2 p-2 pl-4 border border-black rounded w-full placeholder:text-base" + onChange={handleFundingNameChange} + className={`mt-2 p-2 pl-4 border rounded w-full placeholder:text-base ${errors.fundingName ? 'border-red-500' : 'border-black'}`} required /> = ({ placeholder="Set your goal in STRKs" value={name} onChange={handleGoal} - className="mt-4 p-2 pl-4 border border-black rounded w-full placeholder:text-base" + className={`mt-4 p-2 pl-4 border rounded w-full placeholder:text-base ${errors.name ? 'border-red-500' : 'border-black'}`} required + min={0} /> + + {/* Error Messages */} + {errors.fundingName && ( +

{errors.fundingName}

+ )} + {errors.name && ( +

{errors.name}

+ )}
); }; diff --git a/frontend/gostarkme-web/components/modules/newfunding/Stages.tsx b/frontend/gostarkme-web/components/modules/newfunding/Stages.tsx index 7a570d9..df37ddd 100644 --- a/frontend/gostarkme-web/components/modules/newfunding/Stages.tsx +++ b/frontend/gostarkme-web/components/modules/newfunding/Stages.tsx @@ -8,12 +8,29 @@ const Stages = () => { const [fundingName, setFundingName] = useState(""); const [name, setName] = useState(""); const [fundingDescription, setFundingDescription] = useState(""); + const [errors, setErrors] = useState({ fundingName: "", name: "" }); const handleNextStep = () => { - if (currentStep === 0 && (!fundingName || !name)) { - return; + // Reset errors + setErrors({ fundingName: "", name: "" }); + + // Validate fields + let hasErrors = false; + if (currentStep === 0) { + if (!fundingName) { + setErrors((prev) => ({ ...prev, fundingName: "Funding name is required." })); + hasErrors = true; + } + if (!name) { + setErrors((prev) => ({ ...prev, name: "The goal is required." })); + hasErrors = true; + } + } + + // If there are no errors, proceed to the next step + if (!hasErrors) { + setCurrentStep((prev) => (prev === 1 ? 0 : prev + 1)); } - setCurrentStep((prev) => (prev === 1 ? 0 : prev + 1)); }; const handleSubmit = () => { @@ -35,6 +52,8 @@ const Stages = () => { setFundingName={setFundingName} name={name} setName={setName} + errors={errors} // Pass errors down + setErrors={setErrors} // Pass setErrors down /> ) : ( Date: Mon, 30 Sep 2024 23:17:32 -0600 Subject: [PATCH 4/4] fix: add back button in new fund fase 2 page --- .../modules/newfunding/DescriptionStep.tsx | 15 ++++++++++++++- .../gostarkme-web/public/icons/arrow-right.png | Bin 0 -> 571 bytes 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 frontend/gostarkme-web/public/icons/arrow-right.png diff --git a/frontend/gostarkme-web/components/modules/newfunding/DescriptionStep.tsx b/frontend/gostarkme-web/components/modules/newfunding/DescriptionStep.tsx index 03e0b10..0cd65d8 100644 --- a/frontend/gostarkme-web/components/modules/newfunding/DescriptionStep.tsx +++ b/frontend/gostarkme-web/components/modules/newfunding/DescriptionStep.tsx @@ -9,8 +9,9 @@ const DescriptionStep: React.FC = ({ fundingDescription, setFundingDescription, }) => ( -
+
Note: You can always edit your funding description later ;) +