* feat: setup checklist schema * feat: scaffold checklist router * feat: add create new checklist modal * feat: create new checklist item * feat: toggle checklist item completed state * feat: update checklist name * feat: delete checklist * feat: show checklists progress on cards * feat: tweak light mode styling * feat: focus item form on creation of new checklist * feat: tweak new checklist item form styling * feat: add checklist activity * feat: show checklist progress on public board page * feat: display checklist items on public card modal * chore: add translations
57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
import { env } from "next-runtime-env";
|
|
|
|
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 `${env("NEXT_PUBLIC_STORAGE_URL")}/${env("NEXT_PUBLIC_AVATAR_BUCKET_NAME")}/${imageOrKey}`;
|
|
};
|