Skip to content

Commit 04c9d8c

Browse files
clean
1 parent 1af87a2 commit 04c9d8c

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

frontend/routes/@[scope]/(_islands)/ScopeMemberLeave.tsx

+23-20
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,21 @@ export function ScopeMemberLeave({
1515
scopeName?: string;
1616
}) {
1717
const scopeInput = useSignal("");
18-
const error = useSignal(true);
18+
const isEmptyInput = useSignal(false);
19+
const isInvalidInput = useSignal(false);
1920

2021
useEffect(() => {
2122
const handler = setTimeout(() => {
2223
validate();
23-
}, 500);
24+
}, 300);
2425

25-
return clearTimeout(handler);
26+
return () => clearTimeout(handler);
2627
}, [scopeInput.value]);
2728

2829
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;
3233
};
3334

3435
return (
@@ -43,35 +44,37 @@ export function ScopeMemberLeave({
4344
scope{isAdmin && " or manage members"}.
4445
</p>
4546
<input type="hidden" name="userId" value={userId} />
46-
{(error.value && scopeInput.value !== "") && (
47+
{(isLastAdmin || isInvalidInput.value) && (
4748
<div class="mt-6 border rounded-md border-red-300 bg-red-50 p-6 text-red-600">
4849
<span class="font-bold text-xl">Warning</span>
4950
<p>
5051
{isLastAdmin &&
5152
"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 &&
5354
"The scope name you entered does not match the scope name."}
5455
</p>
5556
</div>
5657
)}
5758
<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+
/>
6972
<button
7073
class="button-danger"
7174
type="submit"
7275
name="action"
7376
value="deleteMember"
74-
disabled={error.value}
77+
disabled={isLastAdmin || isInvalidInput.value || isEmptyInput.value}
7578
>
7679
Leave
7780
<TbArrowRightFromArc class="size-5 ml-2 rotate-180" />

0 commit comments

Comments
 (0)