@@ -4,62 +4,104 @@ import {
44 TextField ,
55 Typography ,
66 Button ,
7+ Box ,
78} from "@mui/material" ;
89import { useState } from "react" ;
10+ import { ErrorSnackbar } from "../common/ErrorSnackbar" ;
911import { Email } from "../consts/Email" ;
1012
1113export const Contact = ( ) => {
1214 const [ subject , setSubject ] = useState ( "" ) ;
1315 const [ email , setEmail ] = useState ( "" ) ;
1416 const [ message , setMessage ] = useState ( "" ) ;
17+ const [ snackbarMessage , setSnackbarMessage ] = useState ( "" ) ;
1518
1619 const handleSubmit = ( e : any ) => {
1720 if ( subject !== "" && email !== "" && message !== "" ) {
1821 e . preventDefault ( ) ;
19- window . location . assign (
20- `mailto:${ Email } ?subject=${ subject } &body=${ message } `
21- ) ;
22- }
22+ try {
23+ window . location . assign (
24+ `mailto:${ Email } ?subject=${ subject } &body=${ message } `
25+ ) ;
26+ setSnackbarMessage ( "Email sent successfully." ) ;
27+ } catch ( e ) {
28+ setSnackbarMessage ( "Email failed to send." ) ;
29+ console . log ( e ) ;
30+ }
31+ } else setSnackbarMessage ( "Please fill out all fields." ) ;
2332 } ;
2433
2534 return (
26- < Container maxWidth = { false } >
27- < Typography
28- variant = "h4"
29- fontWeight = { "bold" }
30- color = { "black" }
31- sx = { { p : "1rem 0 3rem" } }
32- >
33- Contact Us
34- </ Typography >
35- < FormControl fullWidth onSubmit = { handleSubmit } >
36- < TextField
37- id = "subject"
38- label = "Subject"
39- value = { subject }
40- onChange = { ( e ) => setSubject ( e ?. target ?. value || "" ) }
41- sx = { { pb : "1rem" } }
35+ < >
36+ { snackbarMessage !== "" && (
37+ < ErrorSnackbar
38+ open = { snackbarMessage !== "" }
39+ handleErrorSnackbarClose = { function ( ) : void {
40+ setSnackbarMessage ( "" ) ;
41+ } }
42+ titleMessage = { snackbarMessage }
43+ bodyMessage = { snackbarMessage }
4244 />
43- < TextField
44- id = "email"
45- label = "Email"
46- type = "email"
47- value = { email }
48- onChange = { ( e ) => setEmail ( e ?. target ?. value || "" ) }
49- sx = { { pb : "1rem" } }
50- />
51- < TextField
52- id = "message"
53- label = "Message"
54- multiline
55- value = { message }
56- onChange = { ( e ) => setMessage ( e ?. target ?. value || "" ) }
57- sx = { { pb : "1rem" } }
58- />
59- < Button variant = "contained" type = "submit" onClick = { handleSubmit } >
60- Submit
61- </ Button >
62- </ FormControl >
63- </ Container >
45+ ) }
46+
47+ < Container >
48+ < Typography
49+ variant = "h4"
50+ fontWeight = { "bold" }
51+ color = { "black" }
52+ sx = { { p : "1rem 0 3rem" } }
53+ >
54+ Contact Us
55+ </ Typography >
56+
57+ < Box
58+ component = "form"
59+ autoComplete = { "true" }
60+ onSubmit = { handleSubmit }
61+ sx = { {
62+ display : "flex" ,
63+ flexDirection : "column" ,
64+ justifyContent : "center" ,
65+ bgcolor : "#44444" ,
66+ } }
67+ >
68+ < TextField
69+ id = "subject"
70+ label = "Subject"
71+ required
72+ value = { subject }
73+ onChange = { ( e ) => setSubject ( e ?. target ?. value || "" ) }
74+ sx = { { pb : "1rem" } }
75+ />
76+ < TextField
77+ id = "email"
78+ label = "Email"
79+ required
80+ type = "email"
81+ value = { email }
82+ onChange = { ( e ) => setEmail ( e ?. target ?. value || "" ) }
83+ sx = { { pb : "1rem" } }
84+ />
85+ < TextField
86+ id = "message"
87+ label = "Message"
88+ required
89+ multiline
90+ value = { message }
91+ onChange = { ( e ) => setMessage ( e ?. target ?. value || "" ) }
92+ sx = { { pb : "1rem" } }
93+ />
94+ < Button
95+ variant = "contained"
96+ type = "submit"
97+ fullWidth
98+ disabled = { subject === "" || email === "" || message === "" }
99+ onClick = { handleSubmit }
100+ >
101+ Submit
102+ </ Button >
103+ </ Box >
104+ </ Container >
105+ </ >
64106 ) ;
65107} ;
0 commit comments