@@ -15,20 +15,21 @@ export function ScopeMemberLeave({
15
15
scopeName ?: string ;
16
16
} ) {
17
17
const scopeInput = useSignal ( "" ) ;
18
- const error = useSignal ( true ) ;
18
+ const isEmptyInput = useSignal ( false ) ;
19
+ const isInvalidInput = useSignal ( false ) ;
19
20
20
21
useEffect ( ( ) => {
21
22
const handler = setTimeout ( ( ) => {
22
23
validate ( ) ;
23
- } , 500 ) ;
24
+ } , 300 ) ;
24
25
25
- return clearTimeout ( handler ) ;
26
+ return ( ) => clearTimeout ( handler ) ;
26
27
} , [ scopeInput . value ] ) ;
27
28
28
29
const validate = ( ) => {
29
- error . value = isLastAdmin ||
30
- ( scopeInput . value !== scopeName && scopeInput . value . length > 0 ) ||
31
- scopeInput . value . length === 0 ;
30
+ isEmptyInput . value = scopeInput . value . length === 0 ;
31
+ isInvalidInput . value = scopeInput . value !== scopeName &&
32
+ scopeInput . value . length > 0 ;
32
33
} ;
33
34
34
35
return (
@@ -43,35 +44,37 @@ export function ScopeMemberLeave({
43
44
scope{ isAdmin && " or manage members" } .
44
45
</ p >
45
46
< input type = "hidden" name = "userId" value = { userId } />
46
- { ( error . value && scopeInput . value !== "" ) && (
47
+ { ( isLastAdmin || isInvalidInput . value ) && (
47
48
< div class = "mt-6 border rounded-md border-red-300 bg-red-50 p-6 text-red-600" >
48
49
< span class = "font-bold text-xl" > Warning</ span >
49
50
< p >
50
51
{ isLastAdmin &&
51
52
"You are the last admin in this scope. You must promote another member to admin before leaving." }
52
- { scopeInput . value !== scopeName && scopeInput . value . length > 0 &&
53
+ { isInvalidInput . value &&
53
54
"The scope name you entered does not match the scope name." }
54
55
</ p >
55
56
</ div >
56
57
) }
57
58
< div class = "mt-4 flex justify-between gap-4" >
58
- { ! isLastAdmin && (
59
- < input
60
- type = "text"
61
- class = "inline-block w-full max-w-sm px-3 input-container text-sm input"
62
- value = { scopeInput . value }
63
- onInput = { ( e ) => {
64
- scopeInput . value = ( e . target as HTMLInputElement ) . value ;
65
- } }
66
- placeholder = "Scope name"
67
- />
68
- ) }
59
+ < input
60
+ type = "text"
61
+ class = "inline-block w-full max-w-sm px-3 input-container text-sm input"
62
+ value = { scopeInput . value }
63
+ onInput = { ( e ) => {
64
+ scopeInput . value = ( e . target as HTMLInputElement ) . value ;
65
+ } }
66
+ placeholder = "Scope name"
67
+ disabled = { isLastAdmin }
68
+ title = { isLastAdmin
69
+ ? "This is the last admin in this scope. Promote another member to admin before demoting this one."
70
+ : undefined }
71
+ />
69
72
< button
70
73
class = "button-danger"
71
74
type = "submit"
72
75
name = "action"
73
76
value = "deleteMember"
74
- disabled = { error . value }
77
+ disabled = { isLastAdmin || isInvalidInput . value || isEmptyInput . value }
75
78
>
76
79
Leave
77
80
< TbArrowRightFromArc class = "size-5 ml-2 rotate-180" />
0 commit comments