mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 02:33:01 +00:00
massive UploadAvatar improvements
This commit is contained in:
@@ -57,11 +57,8 @@ function Account() {
|
|||||||
return (
|
return (
|
||||||
<SettingsPageLayout title="Account">
|
<SettingsPageLayout title="Account">
|
||||||
<form onSubmit={handleSubmit} className="flex flex-col p-4 gap-2 w-sm border">
|
<form onSubmit={handleSubmit} className="flex flex-col p-4 gap-2 w-sm border">
|
||||||
<h2 className="text-xl font-600 mb-2">Account Details</h2>
|
<h2 className="text-xl font-600 mb-2 text-center">Account Details</h2>
|
||||||
<div>
|
<UploadAvatar avatarURL={avatarURL} onAvatarUploaded={setAvatarUrl} />
|
||||||
<Label className="mb-4 block">Avatar</Label>
|
|
||||||
<UploadAvatar avatarURL={avatarURL} onAvatarUploaded={setAvatarUrl} />
|
|
||||||
</div>
|
|
||||||
<Field
|
<Field
|
||||||
label="Full Name"
|
label="Full Name"
|
||||||
value={name}
|
value={name}
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import { Button } from "@/components/ui/button";
|
|||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
|
SelectGroup,
|
||||||
SelectItem,
|
SelectItem,
|
||||||
|
SelectLabel,
|
||||||
SelectSeparator,
|
SelectSeparator,
|
||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
@@ -40,20 +42,23 @@ export function OrganisationSelect({
|
|||||||
onOpenChange={setOpen}
|
onOpenChange={setOpen}
|
||||||
>
|
>
|
||||||
<SelectTrigger className="text-sm" isOpen={open}>
|
<SelectTrigger className="text-sm" isOpen={open}>
|
||||||
<SelectValue
|
<SelectValue placeholder={placeholder} />
|
||||||
placeholder={
|
|
||||||
selectedOrganisation ? `O: ${selectedOrganisation.Organisation.name}` : placeholder
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent side="bottom" position="popper">
|
<SelectContent side="bottom" position="popper">
|
||||||
{organisations.map((organisation) => (
|
<SelectGroup>
|
||||||
<SelectItem key={organisation.Organisation.id} value={`${organisation.Organisation.id}`}>
|
<SelectLabel>Organisations</SelectLabel>
|
||||||
{organisation.Organisation.name}
|
{organisations.map((organisation) => (
|
||||||
</SelectItem>
|
<SelectItem
|
||||||
))}
|
key={organisation.Organisation.id}
|
||||||
|
value={`${organisation.Organisation.id}`}
|
||||||
|
>
|
||||||
|
{organisation.Organisation.name}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
|
||||||
|
{organisations.length > 0 && <SelectSeparator />}
|
||||||
|
</SelectGroup>
|
||||||
|
|
||||||
{organisations.length > 0 && <SelectSeparator />}
|
|
||||||
<CreateOrganisation
|
<CreateOrganisation
|
||||||
trigger={
|
trigger={
|
||||||
<Button variant="ghost" className={"w-full"} size={"sm"}>
|
<Button variant="ghost" className={"w-full"} size={"sm"}>
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import { Button } from "@/components/ui/button";
|
|||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
|
SelectGroup,
|
||||||
SelectItem,
|
SelectItem,
|
||||||
|
SelectLabel,
|
||||||
SelectSeparator,
|
SelectSeparator,
|
||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
@@ -42,17 +44,18 @@ export function ProjectSelect({
|
|||||||
onOpenChange={setOpen}
|
onOpenChange={setOpen}
|
||||||
>
|
>
|
||||||
<SelectTrigger className="text-sm" isOpen={open}>
|
<SelectTrigger className="text-sm" isOpen={open}>
|
||||||
<SelectValue
|
<SelectValue placeholder={placeholder} />
|
||||||
placeholder={selectedProject ? `P: ${selectedProject.Project.name}` : placeholder}
|
|
||||||
/>
|
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent side="bottom" position="popper" align={"start"}>
|
<SelectContent side="bottom" position="popper" align={"start"}>
|
||||||
{projects.map((project) => (
|
<SelectGroup>
|
||||||
<SelectItem key={project.Project.id} value={`${project.Project.id}`}>
|
<SelectLabel>Projects</SelectLabel>
|
||||||
{project.Project.name}
|
{projects.map((project) => (
|
||||||
</SelectItem>
|
<SelectItem key={project.Project.id} value={`${project.Project.id}`}>
|
||||||
))}
|
{project.Project.name}
|
||||||
{projects.length > 0 && <SelectSeparator />}
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
{projects.length > 0 && <SelectSeparator />}
|
||||||
|
</SelectGroup>
|
||||||
<CreateProject
|
<CreateProject
|
||||||
organisationId={organisationId}
|
organisationId={organisationId}
|
||||||
trigger={
|
trigger={
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { Edit } from "lucide-react";
|
||||||
import { useRef, useState } from "react";
|
import { useRef, useState } from "react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
@@ -18,6 +19,7 @@ export function UploadAvatar({
|
|||||||
const [uploading, setUploading] = useState(false);
|
const [uploading, setUploading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
const [showEdit, setShowEdit] = useState(false);
|
||||||
|
|
||||||
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const file = e.target.files?.[0];
|
const file = e.target.files?.[0];
|
||||||
@@ -40,9 +42,23 @@ export function UploadAvatar({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn("flex items-center gap-4", className)}>
|
<div className={cn("flex flex-col items-center gap-4", className)}>
|
||||||
{avatarURL && (
|
{avatarURL && (
|
||||||
<img src={avatarURL} alt="Avatar" className="w-16 h-16 rounded-full border object-cover" />
|
<Button
|
||||||
|
variant="dummy"
|
||||||
|
type="button"
|
||||||
|
onClick={() => fileInputRef.current?.click()}
|
||||||
|
onMouseOver={() => setShowEdit(true)}
|
||||||
|
onMouseOut={() => setShowEdit(false)}
|
||||||
|
className="w-24 h-24 rounded-full border-1 p-0 relative overflow-hidden"
|
||||||
|
>
|
||||||
|
<img src={avatarURL} alt="Avatar" className={cn("rounded-full")} />
|
||||||
|
{showEdit && (
|
||||||
|
<div className="absolute inset-0 flex items-center justify-center bg-black/40">
|
||||||
|
<Edit className="size-6 text-white drop-shadow-md" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
)}
|
)}
|
||||||
<input
|
<input
|
||||||
type="file"
|
type="file"
|
||||||
@@ -51,14 +67,17 @@ export function UploadAvatar({
|
|||||||
accept="image/png,image/jpeg,image/webp,image/gif"
|
accept="image/png,image/jpeg,image/webp,image/gif"
|
||||||
className="hidden"
|
className="hidden"
|
||||||
/>
|
/>
|
||||||
<Button
|
|
||||||
variant="outline"
|
{!avatarURL && (
|
||||||
type="button"
|
<Button
|
||||||
onClick={() => fileInputRef.current?.click()}
|
variant="outline"
|
||||||
disabled={uploading}
|
type="button"
|
||||||
>
|
onClick={() => fileInputRef.current?.click()}
|
||||||
{uploading ? "Uploading..." : label || avatarURL ? "Change Avatar" : "Upload Avatar"}
|
disabled={uploading}
|
||||||
</Button>
|
>
|
||||||
|
{uploading ? "Uploading..." : label || avatarURL ? "Change Avatar" : "Upload Avatar"}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
{error && <Label className="text-destructive text-sm">{error}</Label>}
|
{error && <Label className="text-destructive text-sm">{error}</Label>}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user