|
1 | | -import { useState } from 'react'; |
| 1 | +import { useRef, useState } from 'react'; |
2 | 2 | import { useSearchParams } from 'next/navigation'; |
3 | | -import ContactUsFormSubscribe from '@/components/ContactUs'; |
4 | | -import ContactUsCards from '@/components/ContactUs/ContactUsCards'; |
5 | | -import styles from '@/styles/pages/contact.module.scss'; |
6 | 3 | import Bracket from '@/components/decorations/Bracket'; |
7 | 4 | import bracketStyles from '@/components/decorations/Bracket/Bracket.module.scss'; |
| 5 | +import ContactUsCards from '@/components/ContactUs/ContactUsCards'; |
| 6 | +import ContactUsFormSubscribe from '@/components/ContactUs'; |
| 7 | +import styles from '@/styles/pages/contact.module.scss'; |
8 | 8 | export default function ContactUs() { |
9 | | - const [message, setMessage] = useState([]); |
| 9 | + const subjectFilled = useRef(false); |
10 | 10 | const searchParams = useSearchParams(); |
| 11 | + const subjectParam = searchParams.get('subject'); |
| 12 | + const [param, setParam] = useState(subjectParam || ''); |
| 13 | + const [message, setMessage] = useState([]); |
| 14 | + |
| 15 | + function updateSubject(state, value) { |
| 16 | + subjectFilled.current = state; |
| 17 | + setParam(value); |
| 18 | + } |
| 19 | + |
| 20 | + subjectParam && !subjectFilled.current && updateSubject(true, subjectParam); |
| 21 | + !subjectParam && subjectFilled.current && updateSubject(false, ''); |
| 22 | + |
11 | 23 | return ( |
12 | 24 | <> |
13 | 25 | <div className={styles.contactUsContainer}> |
14 | 26 | <div className={styles.formWrapper}> |
15 | 27 | <div className={styles.formAndDecorations}> |
16 | 28 | <Bracket className={bracketStyles.yellowBracket} /> |
17 | 29 | <ContactUsFormSubscribe |
18 | | - subject={searchParams.get('subject')} |
| 30 | + key={param} |
| 31 | + subject={param} |
19 | 32 | setMsg={setMessage} |
20 | 33 | /> |
21 | 34 | <img |
|
0 commit comments