1
- import { TextInput , NumberInput , Button , Stack , Group } from '@mantine/core' ;
1
+ import { TextInput , NumberInput , Button , Stack , Group , Paper , Text } from '@mantine/core' ;
2
2
import { useForm } from '@mantine/form' ;
3
- import { useEffect , useState } from 'react' ;
3
+ import { useEffect } from 'react' ;
4
4
5
5
interface SettingsFormProps {
6
- initialNtfyTopic : string ;
7
6
initialNtfyServerAddress : string ;
8
7
initialCheckInterval : number ;
9
- onSubmit : ( ntfyTopic : string , ntfyServerAddress : string , checkInterval : number ) => void ;
8
+ initialDefaultNtfyTopic : string ;
9
+ onSubmit : ( ntfyServerAddress : string , checkInterval : number , defaultNtfyTopic : string ) => void ;
10
10
}
11
11
12
12
export function SettingsForm ( {
13
- initialNtfyTopic,
14
13
initialNtfyServerAddress,
15
14
initialCheckInterval,
15
+ initialDefaultNtfyTopic,
16
16
onSubmit,
17
17
} : SettingsFormProps ) {
18
- const [ isTesting , setIsTesting ] = useState ( false ) ;
19
18
const form = useForm ( {
20
19
initialValues : {
21
- ntfyTopic : initialNtfyTopic ,
22
20
ntfyServerAddress : initialNtfyServerAddress ,
23
21
checkInterval : initialCheckInterval ,
22
+ defaultNtfyTopic : initialDefaultNtfyTopic ,
24
23
} ,
25
24
validate : {
26
- ntfyTopic : ( value ) =>
27
- value . length === 0 ? 'Ntfy topic is required' : null ,
28
25
ntfyServerAddress : ( value ) =>
29
- value . length === 0 ? 'Ntfy server address is required' : null ,
26
+ ! value || value . trim ( ) . length === 0 ? 'Ntfy server address is required' : null ,
30
27
checkInterval : ( value ) =>
31
- value < 1 ? 'Check interval must be at least 1 minute' : null ,
28
+ ! value || value < 1 ? 'Check interval must be at least 1 minute' : null ,
29
+ defaultNtfyTopic : ( value ) =>
30
+ ! value || value . trim ( ) . length === 0 ? 'Default ntfy topic is required' : null ,
32
31
} ,
33
32
} ) ;
34
33
35
34
useEffect ( ( ) => {
36
35
form . setValues ( {
37
- ntfyTopic : initialNtfyTopic ,
38
36
ntfyServerAddress : initialNtfyServerAddress ,
39
37
checkInterval : initialCheckInterval ,
38
+ defaultNtfyTopic : initialDefaultNtfyTopic ,
40
39
} ) ;
41
- } , [ initialNtfyTopic , initialNtfyServerAddress , initialCheckInterval ] ) ;
42
-
43
- const handleTestNotification = async ( ) => {
44
- if ( ! form . isValid ( ) ) return ;
45
-
46
- try {
47
- setIsTesting ( true ) ;
48
- await fetch ( '/api/test-notification' , { method : 'POST' } ) ;
49
- } catch ( error ) {
50
- console . error ( 'Failed to send test notification:' , error ) ;
51
- } finally {
52
- setIsTesting ( false ) ;
53
- }
54
- } ;
40
+ } , [ initialNtfyServerAddress , initialCheckInterval , initialDefaultNtfyTopic ] ) ;
55
41
56
42
return (
57
- < Stack h = "100%" style = { { flex : 1 } } >
58
- < form onSubmit = { form . onSubmit ( ( values ) => onSubmit ( values . ntfyTopic , values . ntfyServerAddress , values . checkInterval ) ) } >
59
- < Stack >
60
- < TextInput
61
- label = "Ntfy Server Address"
62
- placeholder = "https://ntfy.sh"
63
- required
64
- { ...form . getInputProps ( 'ntfyServerAddress' ) }
65
- />
66
- < TextInput
67
- label = "Ntfy Topic"
68
- placeholder = "your-topic-name"
69
- required
70
- { ...form . getInputProps ( 'ntfyTopic' ) }
71
- />
72
- < NumberInput
73
- label = "Check Interval (minutes)"
74
- placeholder = "15"
75
- min = { 1 }
76
- required
77
- { ...form . getInputProps ( 'checkInterval' ) }
78
- />
79
- < Group justify = "space-between" >
80
- < Button onClick = { handleTestNotification } loading = { isTesting } variant = "light" >
81
- Test Notification
82
- </ Button >
83
- < Button type = "submit" > Save Settings</ Button >
84
- </ Group >
85
- </ Stack >
86
- </ form >
87
- </ Stack >
43
+ < form onSubmit = { form . onSubmit ( ( values ) => onSubmit ( values . ntfyServerAddress , values . checkInterval , values . defaultNtfyTopic ) ) } >
44
+ < Stack >
45
+ { /* Notification Settings Section */ }
46
+ < Paper withBorder p = "md" >
47
+ < Stack >
48
+ < Text fw = { 500 } size = "sm" > Ntfy Settings</ Text >
49
+ < TextInput
50
+ label = "Server Address"
51
+ placeholder = "https://ntfy.sh"
52
+ required
53
+ { ...form . getInputProps ( 'ntfyServerAddress' ) }
54
+ />
55
+ < TextInput
56
+ label = "Default Topic"
57
+ placeholder = "rss"
58
+ description = "Used when a feed doesn't have a specific topic configured"
59
+ required
60
+ { ...form . getInputProps ( 'defaultNtfyTopic' ) }
61
+ />
62
+ </ Stack >
63
+ </ Paper >
64
+
65
+ { /* Feed Check Settings Section */ }
66
+ < Paper withBorder p = "md" >
67
+ < Stack >
68
+ < Text fw = { 500 } size = "sm" > Monitoring Settings</ Text >
69
+ < NumberInput
70
+ label = "Check Interval"
71
+ description = "How often to check feeds for new posts (in minutes)"
72
+ placeholder = "15"
73
+ min = { 1 }
74
+ required
75
+ { ...form . getInputProps ( 'checkInterval' ) }
76
+ />
77
+ </ Stack >
78
+ </ Paper >
79
+
80
+ < Group justify = "flex-end" mt = "md" >
81
+ < Button type = "submit" > Save Settings</ Button >
82
+ </ Group >
83
+ </ Stack >
84
+ </ form >
88
85
) ;
89
86
}
0 commit comments