Skip to content

Commit

Permalink
Add keep scores to admin delete user
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-g committed Nov 12, 2023
1 parent 477a01b commit 9c07ac1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions .todo
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Social login
- On logout, reset theme
- Replace autocompletes with selects where appropriate
- Fix dark mode map popup

# Before premium
- Map designs for themes
Expand Down
2 changes: 1 addition & 1 deletion app/models/group.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ export async function deleteGroupMember({

let createdAnonymousUserId: string | null = null
if (!deleteScores) {
const createdAnonymousUser = await createAnonymousUser("name", groupId, requestedByUserId)
const createdAnonymousUser = await createAnonymousUser(`Anonymous user`, groupId, requestedByUserId)
if (!createdAnonymousUser) {
return { error: "Something went wrong" }
}
Expand Down
28 changes: 24 additions & 4 deletions app/routes/_layout.groups.$groupId.settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ type RemoveMemberActionProps = {
}
const RemoveMemberAction = ({ member }: RemoveMemberActionProps) => {
const fetcher = useFetcher()
const [deleteScores, setDeleteScores] = useState(false)

const isAnonymousUser = member.user.role === "ANONYMOUS"

return (
<Dialog>
Expand All @@ -303,11 +306,28 @@ const RemoveMemberAction = ({ member }: RemoveMemberActionProps) => {
<Dialog.Content>
<Dialog.Close />
<Dialog.Title>Are you sure you want to remove {member.user.name} from the club?</Dialog.Title>
<DialogDescription>
This will delete all their scores and comments. This action <strong>cannot be undone</strong>!
</DialogDescription>
<Spacer size={16} />
<fetcher.Form action="/api/groups/member" method="post">
<DialogDescription>
This will delete {isAnonymousUser ? "all their scores and comments" : "the user"}. This action{" "}
<strong>cannot be undone</strong>!
<Spacer size={16} />
{!isAnonymousUser && (
<Stack gap={8} axis="horizontal" align="center">
<Checkbox
id="deleteScores"
name="deleteScores"
checked={deleteScores}
onCheckedChange={(checked) => setDeleteScores(checked === true)}
/>
<label htmlFor="deleteScores">Delete scores from group</label>
<Help>
This also deletes their scores and comments from the group. This action is{" "}
<strong>permanent</strong>.
</Help>
</Stack>
)}
</DialogDescription>
<Spacer size={16} />
<input name="userId" value={member.userId} type="hidden" />
<input name="groupId" value={member.groupId} type="hidden" />
<input name="action" value={"delete"} type="hidden" />
Expand Down
6 changes: 6 additions & 0 deletions app/routes/api.groups.member.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
}

if (action === "delete") {
const deleteScores = formData.get("deleteScores")
if (deleteScores && typeof deleteScores !== "string") {
return json<ActionData>({ ok: false, errors: { error: "Something went wrong" } }, { status: 400 })
}

await deleteGroupMember({
groupId,
userId,
requestedByUserId: currentUserId,
deleteScores: deleteScores === "on",
})
return json<ActionData>({ ok: true })
}
Expand Down

0 comments on commit 9c07ac1

Please sign in to comment.