* refactor: replace presigned URL uploads with backend upload endpoints * feat: update avatar upload to use new endpoint * refactor: use createS3Client in auth hooks * feat: generate presigned URLs for avatars * fix: show avatar image in user menu * fix: hide tooltip if content is empty * fix: support external avatar URLs in generateAvatarUrl * fix: remove content type restriction on attachments
55 lines
1.2 KiB
TypeScript
55 lines
1.2 KiB
TypeScript
export const formatToArray = (
|
|
value: string | string[] | undefined,
|
|
): string[] => {
|
|
if (Array.isArray(value)) {
|
|
return value.filter((item) => item !== undefined);
|
|
}
|
|
return value ? [value] : [];
|
|
};
|
|
|
|
export const inferInitialsFromEmail = (email: string) => {
|
|
const localPart = email.split("@")[0];
|
|
if (!localPart) return "";
|
|
const separators = /[._-]/;
|
|
const parts = localPart.split(separators);
|
|
|
|
if (parts.length > 1) {
|
|
return (
|
|
(parts[0]?.[0] ?? "") + (parts[parts.length - 1]?.[0] ?? "")
|
|
).toUpperCase();
|
|
} else {
|
|
return localPart.slice(0, 2).toUpperCase();
|
|
}
|
|
};
|
|
|
|
export const getInitialsFromName = (name: string) => {
|
|
return name
|
|
.split(" ")
|
|
.map((namePart) => namePart.charAt(0).toUpperCase())
|
|
.join("");
|
|
};
|
|
|
|
export const formatMemberDisplayName = (
|
|
name: string | null,
|
|
email: string | null,
|
|
) => {
|
|
if (name) return name;
|
|
if (!email) return "";
|
|
|
|
const localPart = email.split("@")[0];
|
|
|
|
if (!localPart) return "";
|
|
|
|
return localPart.replace(/[_-]/g, ".");
|
|
};
|
|
|
|
export const getAvatarUrl = (imageOrKey: string | null) => {
|
|
if (!imageOrKey) return "";
|
|
|
|
if (imageOrKey.startsWith("http://") || imageOrKey.startsWith("https://")) {
|
|
return imageOrKey;
|
|
}
|
|
|
|
return "";
|
|
};
|