Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
50a33f1bdf
commit
4ecd92b1e8
@@ -36,9 +36,16 @@ function ProfilePage() {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [uploading, setUploading] = useState(false);
|
||||
const [uploadingSig, setUploadingSig] = useState(false);
|
||||
const [form, setForm] = useState({ ...EMPTY });
|
||||
const [email, setEmail] = useState("");
|
||||
const fileInput = useRef<HTMLInputElement>(null);
|
||||
const sigInput = useRef<HTMLInputElement>(null);
|
||||
|
||||
// Derive a public preview URL for the saved signature image
|
||||
const signatureUrl = form.signature_image_path
|
||||
? supabase.storage.from("avatars").getPublicUrl(form.signature_image_path).data.publicUrl
|
||||
: "";
|
||||
|
||||
const load = async () => {
|
||||
if (!user) return;
|
||||
@@ -50,13 +57,16 @@ function ProfilePage() {
|
||||
.maybeSingle();
|
||||
if (data) {
|
||||
setEmail(data.email || user.email || "");
|
||||
const d = data as any;
|
||||
setForm({
|
||||
full_name: data.full_name ?? "",
|
||||
title: (data as any).title ?? "",
|
||||
phone: (data as any).phone ?? "",
|
||||
bio: (data as any).bio ?? "",
|
||||
timezone: (data as any).timezone ?? "",
|
||||
avatar_url: (data as any).avatar_url ?? "",
|
||||
title: d.title ?? "",
|
||||
phone: d.phone ?? "",
|
||||
bio: d.bio ?? "",
|
||||
timezone: d.timezone ?? "",
|
||||
avatar_url: d.avatar_url ?? "",
|
||||
signature_block: d.signature_block ?? "",
|
||||
signature_image_path: d.signature_image_path ?? "",
|
||||
});
|
||||
}
|
||||
setLoading(false);
|
||||
@@ -118,6 +128,50 @@ function ProfilePage() {
|
||||
toast.success("Photo removed");
|
||||
};
|
||||
|
||||
const onSignatureFile = async (file: File) => {
|
||||
if (!user) return;
|
||||
if (file.size > 2 * 1024 * 1024) {
|
||||
toast.error("Signature image must be under 2 MB");
|
||||
return;
|
||||
}
|
||||
setUploadingSig(true);
|
||||
const ext = (file.name.split(".").pop() || "png").toLowerCase();
|
||||
const path = `${user.id}/signature-${Date.now()}.${ext}`;
|
||||
const { error } = await supabase.storage
|
||||
.from("avatars")
|
||||
.upload(path, file, { upsert: true, contentType: file.type, cacheControl: "3600" });
|
||||
if (error) {
|
||||
setUploadingSig(false);
|
||||
toast.error("Upload failed", { description: error.message });
|
||||
return;
|
||||
}
|
||||
const { error: upErr } = await supabase
|
||||
.from("profiles")
|
||||
.update({ signature_image_path: path } as any)
|
||||
.eq("id", user.id);
|
||||
setUploadingSig(false);
|
||||
if (upErr) {
|
||||
toast.error("Could not save signature", { description: upErr.message });
|
||||
return;
|
||||
}
|
||||
setForm((f) => ({ ...f, signature_image_path: path }));
|
||||
toast.success("Signature image saved");
|
||||
};
|
||||
|
||||
const removeSignatureImage = async () => {
|
||||
if (!user) return;
|
||||
const { error } = await supabase
|
||||
.from("profiles")
|
||||
.update({ signature_image_path: null } as any)
|
||||
.eq("id", user.id);
|
||||
if (error) {
|
||||
toast.error("Could not remove", { description: error.message });
|
||||
return;
|
||||
}
|
||||
setForm((f) => ({ ...f, signature_image_path: "" }));
|
||||
toast.success("Signature image removed");
|
||||
};
|
||||
|
||||
const save = async () => {
|
||||
if (!user) return;
|
||||
setSaving(true);
|
||||
@@ -129,7 +183,8 @@ function ProfilePage() {
|
||||
phone: form.phone || null,
|
||||
bio: form.bio || null,
|
||||
timezone: form.timezone || null,
|
||||
})
|
||||
signature_block: form.signature_block || null,
|
||||
} as any)
|
||||
.eq("id", user.id);
|
||||
setSaving(false);
|
||||
if (error) {
|
||||
|
||||
Reference in New Issue
Block a user