-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: admins can edit user, other bug fixes and imporvements in admin…
… dash, homepage css changes
- Loading branch information
1 parent
51aeee3
commit e3d9eb8
Showing
8 changed files
with
234 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { SubmitButton } from "@/components/submit-button"; | ||
import { Checkbox } from "@/components/ui/checkbox"; | ||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog"; | ||
import { Input } from "@/components/ui/input"; | ||
import { Label } from "@/components/ui/label"; | ||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; | ||
import authClient from "@/lib/auth-client"; | ||
import type { SelectUser } from "@stardust/db"; | ||
import { toast } from "sonner"; | ||
import { resetPassword, updateUser } from "./actions"; | ||
|
||
export interface Props { | ||
user: SelectUser; | ||
setOpen: React.Dispatch<React.SetStateAction<boolean>>; | ||
open: boolean; | ||
} | ||
export function ResetPasswordDialog({ user, open, setOpen }: Props) { | ||
return ( | ||
<Dialog open={open} onOpenChange={setOpen}> | ||
<DialogContent> | ||
<DialogHeader> | ||
<DialogTitle>Reset password for {user.name || user.email}</DialogTitle> | ||
</DialogHeader> | ||
<form | ||
action={(data) => | ||
toast.promise( | ||
async () => { | ||
const res = await resetPassword(user.id, data); | ||
if (res?.error) throw new Error(res.error); | ||
return res; | ||
}, | ||
{ | ||
loading: "Resetting password...", | ||
success: "Password reset", | ||
error: (error) => `Failed to reset password: ${error.message}`, | ||
finally: () => setOpen(false), | ||
}, | ||
) | ||
} | ||
className="flex flex-col gap-2 w-full" | ||
> | ||
<Label htmlFor="new-password">New password</Label> | ||
<Input | ||
id="new-password" | ||
placeholder="New password" | ||
name="new-password" | ||
minLength={8} | ||
type="password" | ||
required | ||
/> | ||
<div className="flex items-center gap-2"> | ||
<Checkbox id="revoke-others" name="revoke-others" defaultChecked /> | ||
<Label htmlFor="revoke-others">Sign out of all other devices</Label> | ||
</div> | ||
<SubmitButton>Submit</SubmitButton> | ||
</form> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} | ||
export function UpdateUserDialog({ user, open, setOpen }: Props) { | ||
return ( | ||
<Dialog open={open} onOpenChange={setOpen}> | ||
<DialogContent> | ||
<DialogHeader> | ||
<DialogTitle>Update {user.name}</DialogTitle> | ||
</DialogHeader> | ||
<form | ||
action={(data) => | ||
toast.promise( | ||
async () => { | ||
const res = await updateUser(user.id, data); | ||
if (res.error) { | ||
throw new Error(res.error); | ||
} | ||
return res; | ||
}, | ||
{ | ||
success: "User updated successfully", | ||
error: (error) => `Failed to update user: ${error.message}`, | ||
finally: () => setOpen(false), | ||
}, | ||
) | ||
} | ||
className="flex flex-col gap-2 w-full" | ||
> | ||
<Label htmlFor="name">Name</Label> | ||
<Input id="name" type="text" name="name" defaultValue={user.name} required /> | ||
<Label htmlFor="email">Email</Label> | ||
<Input id="email" type="email" name="email" defaultValue={user.email} required /> | ||
<Label htmlFor="image">Image</Label> | ||
<Input id="image" type="url" name="image" defaultValue={user.image || undefined} /> | ||
<Label htmlFor="role">Role</Label> | ||
<Select required name="role" defaultValue={user.role}> | ||
<SelectTrigger id="role"> | ||
<SelectValue /> | ||
</SelectTrigger> | ||
<SelectContent> | ||
<SelectItem value="user">User</SelectItem> | ||
<SelectItem value="admin">Admin</SelectItem> | ||
</SelectContent> | ||
</Select> | ||
<SubmitButton>Save</SubmitButton> | ||
</form> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} |
Oops, something went wrong.