1- ' use client' ;
1+ " use client" ;
22
3- import { useState , useEffect } from ' react' ;
3+ import { useState , useEffect } from " react" ;
44
5- const PASSWORD = 'password' ; // Replace with a strong password
5+ const PASSWORD = process . env . SUBMISSIONS_PASSWORD ; // Replace with a strong password
6+
7+ interface Submission {
8+ name : string ;
9+ email : string ;
10+ message : string ;
11+ date : string ;
12+ }
613
714export default function ContactSubmissions ( ) {
8- const [ password , setPassword ] = useState ( '' ) ;
15+ const [ password , setPassword ] = useState ( "" ) ;
916 const [ authenticated , setAuthenticated ] = useState ( false ) ;
10- const [ submissions , setSubmissions ] = useState ( [ ] ) ;
11- const [ error , setError ] = useState ( '' ) ;
17+ const [ submissions , setSubmissions ] = useState < Submission [ ] > ( [ ] ) ;
18+ const [ error , setError ] = useState ( "" ) ;
1219
1320 const handlePasswordSubmit = ( e : React . FormEvent ) => {
1421 e . preventDefault ( ) ;
1522 if ( password === PASSWORD ) {
1623 setAuthenticated ( true ) ;
1724 } else {
18- setError ( ' Incorrect password' ) ;
25+ setError ( " Incorrect password" ) ;
1926 }
2027 } ;
2128
2229 useEffect ( ( ) => {
2330 if ( authenticated ) {
2431 const fetchSubmissions = async ( ) => {
2532 try {
26- const response = await fetch ( ' /api/contact-submissions' ) ;
33+ const response = await fetch ( " /api/contact-submissions" ) ;
2734 if ( response . ok ) {
2835 const data = await response . json ( ) ;
2936 setSubmissions ( data ) ;
3037 } else {
31- setError ( ' Failed to fetch submissions.' ) ;
38+ setError ( " Failed to fetch submissions." ) ;
3239 }
3340 } catch ( error ) {
34- setError ( ' Failed to fetch submissions.' ) ;
41+ setError ( " Failed to fetch submissions." ) ;
3542 }
3643 } ;
3744 fetchSubmissions ( ) ;
@@ -41,10 +48,16 @@ export default function ContactSubmissions() {
4148 if ( ! authenticated ) {
4249 return (
4350 < div className = "flex items-center justify-center h-screen" >
44- < form onSubmit = { handlePasswordSubmit } className = "bg-white dark:bg-gray-800 p-8 rounded-lg shadow-lg" >
51+ < form
52+ onSubmit = { handlePasswordSubmit }
53+ className = "bg-white dark:bg-gray-800 p-8 rounded-lg shadow-lg"
54+ >
4555 < h2 className = "text-2xl font-bold mb-4" > Enter Password</ h2 >
4656 < div className = "mb-4" >
47- < label htmlFor = "password" a className = "block text-sm font-medium text-gray-700 dark:text-gray-300" >
57+ < label
58+ htmlFor = "password"
59+ className = "block text-sm font-medium text-gray-700 dark:text-gray-300"
60+ >
4861 Password
4962 </ label >
5063 < input
@@ -74,12 +87,24 @@ export default function ContactSubmissions() {
7487 < p > No submissions yet.</ p >
7588 ) : (
7689 < div className = "space-y-4" >
77- { submissions . map ( ( submission : any , index : number ) => (
78- < div key = { index } className = "bg-white dark:bg-gray-800 p-4 rounded-lg shadow" >
79- < p > < strong > Name:</ strong > { submission . name } </ p >
80- < p > < strong > Email:</ strong > { submission . email } </ p >
81- < p > < strong > Message:</ strong > { submission . message } </ p >
82- < p > < strong > Date:</ strong > { new Date ( submission . date ) . toLocaleString ( ) } </ p >
90+ { submissions . map ( ( submission , index ) => (
91+ < div
92+ key = { index }
93+ className = "bg-white dark:bg-gray-800 p-4 rounded-lg shadow"
94+ >
95+ < p >
96+ < strong > Name:</ strong > { submission . name }
97+ </ p >
98+ < p >
99+ < strong > Email:</ strong > { submission . email }
100+ </ p >
101+ < p >
102+ < strong > Message:</ strong > { submission . message }
103+ </ p >
104+ < p >
105+ < strong > Date:</ strong > { " " }
106+ { new Date ( submission . date ) . toLocaleString ( ) }
107+ </ p >
83108 </ div >
84109 ) ) }
85110 </ div >
0 commit comments