1
1
"use client" ;
2
2
3
- import { useState , useCallback } from "react" ;
3
+ import { useState , useCallback , useRef } from "react" ;
4
4
import { motion , AnimatePresence } from "framer-motion" ;
5
5
import { NotificationConfig , TabType , FieldType } from "./types" ;
6
6
import { Tab } from "./form/Tab" ;
7
7
import { ChatTab } from "./form/ChatTab" ;
8
8
import { ActionBarTab } from "./form/ActionBarTab" ;
9
9
import { TitleTab } from "./form/TitleTab" ;
10
- import { SoundTab } from "./form/SoundTab" ;
10
+ import { SoundTab , SoundTabRef } from "./form/SoundTab" ;
11
11
import { AdvancedTab } from "./form/AdvancedTab" ;
12
12
import { validateField , validateForm } from "./form/validation" ;
13
13
@@ -22,15 +22,14 @@ export function NotificationForm({
22
22
} : NotificationFormProps ) {
23
23
const [ activeTab , setActiveTab ] = useState < TabType > ( "chat" ) ;
24
24
const [ errors , setErrors ] = useState < Record < string , string > > ( { } ) ;
25
-
25
+ const soundTabRef = useRef < SoundTabRef > ( null ) ;
26
26
27
27
const handleChange = useCallback ( ( field : FieldType , value : string | boolean ) => {
28
28
setNotification ( {
29
29
...notification ,
30
30
[ field ] : value ,
31
31
} ) ;
32
32
33
-
34
33
if ( [ "fadeIn" , "stay" , "fadeOut" , "volume" , "pitch" , "sound" ] . includes ( field ) ) {
35
34
const error = validateField ( field , value as string ) ;
36
35
setErrors ( ( prev ) => ( {
@@ -45,8 +44,10 @@ export function NotificationForm({
45
44
}
46
45
} , [ notification , setNotification , errors ] ) ;
47
46
48
-
49
47
const resetForm = useCallback ( ( ) => {
48
+
49
+ soundTabRef . current ?. stopSound ( ) ;
50
+
50
51
setNotification ( {
51
52
chat : "" ,
52
53
actionbar : "" ,
@@ -64,7 +65,6 @@ export function NotificationForm({
64
65
setErrors ( { } ) ;
65
66
} , [ setNotification ] ) ;
66
67
67
-
68
68
const renderTabContent = ( ) => {
69
69
switch ( activeTab ) {
70
70
case "chat" :
@@ -74,7 +74,7 @@ export function NotificationForm({
74
74
case "title" :
75
75
return < TitleTab notification = { notification } onChange = { handleChange } errors = { errors } /> ;
76
76
case "sound" :
77
- return < SoundTab notification = { notification } onChange = { handleChange } errors = { errors } /> ;
77
+ return < SoundTab ref = { soundTabRef } notification = { notification } onChange = { handleChange } errors = { errors } /> ;
78
78
case "advanced" :
79
79
return < AdvancedTab notification = { notification } onChange = { handleChange } /> ;
80
80
default :
@@ -122,7 +122,7 @@ export function NotificationForm({
122
122
transition = { { duration : 0.2 , delay : 0.1 } }
123
123
>
124
124
< motion . button
125
- className = "rounded-md bg-gray-200 px-4 py-2 text-gray-800 hover:bg-gray-300 focus:outline-none focus:ring-2 focus:ring-gray-500 focus:ring-offset-2 dark:bg-gray-700 dark:text-gray-200 dark:hover:bg-gray-600"
125
+ className = "rounded-md bg-gray-200 px-4 py-2 text-gray-800 hover:bg-gray-300 dark:bg-gray-700 dark:text-gray-200 dark:hover:bg-gray-600"
126
126
onClick = { resetForm }
127
127
whileHover = { { scale : 1.05 } }
128
128
whileTap = { { scale : 0.95 } }
0 commit comments