@@ -6,6 +6,7 @@ import starsIconGroupWhite from "../../src/assets/starsIconGroupWhite.svg";
66import Input from " ../components/Input.astro" ;
77import Button from " ../components/Button.astro" ;
88import { getLangFromUrl , useTranslations } from " ../i18n/utils" ;
9+ import Textarea from " ../components/Textarea.astro" ;
910
1011const lang = getLangFromUrl (Astro .url );
1112const t = useTranslations (lang );
@@ -22,7 +23,7 @@ const t = useTranslations(lang);
2223 <div class =" formTopBar" >
2324 <Image src ={ LogoDark } alt =" logo" width ={ 30 } height ={ 30 } />
2425 </div >
25- <form class =" formContainer" >
26+ <form class =" formContainer" id = " form " >
2627 <div class =" formSections" >
2728 <div class =" formTopSection" >
2829 <div class =" formTopSectionInput" >
@@ -32,20 +33,31 @@ const t = useTranslations(lang);
3233 <Input type =" text" placeholder ={ t (" surname" )} name =" surname" />
3334 </div >
3435 <div class =" formTopSectionInput" >
35- <Input type =" tel" placeholder ={ t (" phone" )} name =" tel" />
36+ <Input
37+ type =" tel"
38+ placeholder ={ t (" phone" )}
39+ name =" phone"
40+ />
3641 </div >
3742 <div class =" formTopSectionInput" >
3843 <Input type =" text" placeholder ={ t (" subject" )} name =" subject" />
3944 </div >
4045 </div >
4146 <div class =" formBottomSection" >
42- <Input type =" email" placeholder ={ t (" email" )} name =" email" />
47+ <Input
48+ type =" email"
49+ placeholder ={ t (" email" )}
50+ name =" email"
51+ />
4352 <Input type =" text" placeholder ={ t (" company" )} name =" company" />
44- <Input type = " text " placeholder ={ t (" content" )} name =" content" />
53+ <Textarea placeholder ={ t (" content" )} name =" content" />
4554 </div >
4655 </div >
56+ <div class =" errorMessageContainer" >
57+ <span id =" errorMessage" ></span >
58+ </div >
4759 <div class =" formButtonContainer" >
48- <Button variant =" primary" id =" formSubmitButton" >{ t (" send" )} </Button >
60+ <Button variant =" primary" type = " submit " id =" formSubmitButton" >{ t (" send" )} </Button >
4961 </div >
5062 </form >
5163 </div >
@@ -65,6 +77,35 @@ const t = useTranslations(lang);
6577 </ul >
6678</div >
6779
80+ <script >
81+ import { type FormFields} from "../types.ts";
82+ import { sendTicket } from "../scripts/api.ts";
83+ import { validateContactForm } from "../scripts/helpers.ts"
84+
85+ const form = document.getElementById("form") as HTMLFormElement;
86+ const errorMessageSpan = document.getElementById("errorMessage");
87+
88+ form?.addEventListener("submit", async (e: SubmitEvent) => {
89+ e.preventDefault();
90+
91+ const formData = new FormData(form);
92+ const data = Object.fromEntries(formData.entries()) as unknown as FormFields;
93+ console.log(data);
94+ const validation = validateContactForm(data);
95+
96+ if(!validation && errorMessageSpan != null){
97+ errorMessageSpan.innerText = "Please ensure all required fields are filled out correctly before submitting.";
98+ return;
99+ }
100+
101+ const response = await sendTicket(data);
102+
103+ // if response is positive, change the view to "sent form view"
104+ })
105+
106+
107+ </script >
108+
68109<style >
69110 .wrapper{
70111 width: 900px;
@@ -85,6 +126,19 @@ const t = useTranslations(lang);
85126 margin-top: 70px;
86127 }
87128
129+ .errorMessageContainer{
130+ width: 100%;
131+ display: flex;
132+ align-items: center;
133+ justify-content: center;
134+ }
135+
136+ #errorMessage{
137+ color: red;
138+ width: 100%;
139+ padding: 0px 20px;
140+ }
141+
88142 .infoWrapper{
89143 display: flex;
90144 flex-direction: column;
@@ -118,6 +172,11 @@ const t = useTranslations(lang);
118172 top: 10%;
119173 opacity: 0.25;
120174 filter: blur(2px);
175+ z-index: -1;
176+ }
177+
178+ .infoWrapper, .formWrapper, .contactWrapper{
179+ z-index: 1;
121180 }
122181
123182 .formWrapper{
0 commit comments