Skip to content

Commit 9d4c06f

Browse files
committed
fix: enable all button click but show error message if something wrong
1 parent d75cbb1 commit 9d4c06f

File tree

4 files changed

+36
-11
lines changed

4 files changed

+36
-11
lines changed

apps/website/src/components/BaseContactForm.astro

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const { onDark, classNames, formId, formClassNames } = Astro.props;
1818
<form
1919
class={classnames(
2020
"group/contact-us flex flex-col gap-2 relative",
21-
formClassNames
21+
formClassNames,
2222
)}
2323
id={formId}
2424
novalidate
@@ -105,17 +105,15 @@ const { onDark, classNames, formId, formClassNames } = Astro.props;
105105
{
106106
"text-secondary": !onDark,
107107
"text-neutral-50": onDark,
108-
}
108+
},
109109
)}
110110
/>
111111
</div>
112112
<button
113113
id="form-submit-button"
114114
class="rounded-md
115115
min-h-14
116-
group-invalid/contact-us:pointer-events-none
117116
group-invalid/contact-us:focus-visible:outline-transparent
118-
group-invalid/contact-us:opacity-70
119117
bg-crocoder-yellow
120118
hover:bg-crocoder-yellow/90
121119
px-[25px] w-full py-4
@@ -126,7 +124,7 @@ const { onDark, classNames, formId, formClassNames } = Astro.props;
126124
text-center
127125
text-secondary
128126
text-base
129-
font-medium mt-6"
127+
font-medium mt-6 cursor-pointer"
130128
>
131129
<span id="submit-content"
132130
>{
@@ -163,7 +161,7 @@ const { onDark, classNames, formId, formClassNames } = Astro.props;
163161
const submitBtnLoader = submitBtn?.querySelectorAll("#submit-loader")[0];
164162

165163
const notificationElem = form?.querySelector(
166-
"#form-notification"
164+
"#form-notification",
167165
) as HTMLElement;
168166

169167
const currentUrl = new URL(window.location.href);
@@ -204,13 +202,28 @@ const { onDark, classNames, formId, formClassNames } = Astro.props;
204202
const consent = formData.get("form-consent");
205203

206204
if (!name || !email || !message || !consent) {
205+
notificationElem.classList.add("text-red-500");
206+
207+
if (!name) {
208+
notificationElem.textContent =
209+
notification.frontmatter.fullnameLength;
210+
} else if (!email) {
211+
notificationElem.textContent =
212+
notification.frontmatter.emailInvalid;
213+
} else if (!message) {
214+
notificationElem.textContent =
215+
notification.frontmatter.projectDescriptionRequired;
216+
} else if (!consent) {
217+
notificationElem.textContent =
218+
notification.frontmatter.consentRequired;
219+
}
207220
return;
208221
}
209222

210223
showLoader();
211224

212225
const apiUrl = new URL(
213-
`${import.meta.env.PUBLIC_API_URL}/api/contact`
226+
`${import.meta.env.PUBLIC_API_URL}/api/contact`,
214227
);
215228
apiUrl.searchParams.set("source", currentUrl.pathname);
216229

apps/website/src/components/staff-agmentation/GetYourPlanForm.astro

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ import "../../styles/loader.css";
7676
text-secondary
7777
text-base
7878
font-medium
79-
group-invalid/contact-us:pointer-events-none
8079
group-invalid/contact-us:focus-visible:outline-transparent
81-
group-invalid/contact-us:opacity-70
8280
bg-crocoder-yellow
8381
hover:bg-crocoder-yellow/90
8482
focus:bg-crocoder-yellow/90
@@ -163,7 +161,19 @@ import "../../styles/loader.css";
163161
const mainChallenge = formData.get("form-challenge");
164162
const expectedStartDate = formData.get("form-start-date");
165163

164+
const emailInput = form.querySelector<HTMLInputElement>("#form-email");
165+
166+
166167
if (!name || !email || !consent) {
168+
notificationElem.classList.add("text-red-500");
169+
170+
if (!name) {
171+
notificationElem.textContent = notification.frontmatter.fullnameLength;
172+
} else if (!email) {
173+
notificationElem.textContent = notification.frontmatter.emailInvalid;
174+
} else if (!consent) {
175+
notificationElem.textContent = notification.frontmatter.consentRequired;
176+
}
167177
return;
168178
}
169179

apps/website/src/components/staff-agmentation/GetYourPlanModal.astro

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ const computedStartDates = (formContent.frontmatter.startDates as string[]).map(
7777
text-secondary
7878
text-base
7979
font-medium
80-
group-invalid/contact-us:pointer-events-none
81-
group-invalid/contact-us:opacity-30
8280
group-invalid/contact-us:focus-visible:bg-[#85a32a]
8381
group-invalid/contact-us:focus-visible:outline-transparent
8482
group-invalid/contact-us:focus:bg-[#85a32a]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
---
22
success: "Thank you for contacting us! We will reach soon."
33
error: "Looks like something went wrong. Please try again."
4+
fullnameLength: "Name must be at least 2 characters."
5+
emailInvalid: "Please enter a valid email address."
6+
consentRequired: "You must agree to the privacy consent before continuing."
7+
projectDescriptionRequired: "Project description is required."
48
---

0 commit comments

Comments
 (0)