Skip to content

Commit 60ab75c

Browse files
committed
fix: Resolve the auto-subject population feature's inconsistent behavior
1 parent 5267fdc commit 60ab75c

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

pages/contact.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
1-
import { useState } from 'react';
1+
import { useRef, useState } from 'react';
22
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';
63
import Bracket from '@/components/decorations/Bracket';
74
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';
88
export default function ContactUs() {
9-
const [message, setMessage] = useState([]);
9+
const subjectFilled = useRef(false);
1010
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+
1123
return (
1224
<>
1325
<div className={styles.contactUsContainer}>
1426
<div className={styles.formWrapper}>
1527
<div className={styles.formAndDecorations}>
1628
<Bracket className={bracketStyles.yellowBracket} />
1729
<ContactUsFormSubscribe
18-
subject={searchParams.get('subject')}
30+
key={param}
31+
subject={param}
1932
setMsg={setMessage}
2033
/>
2134
<img

0 commit comments

Comments
 (0)