feature: treatment frontend wired with the newly implemented backend. no mocked data no more.
This commit is contained in:
40
frontend/src/components/treatment/caseSendLabel.ts
Normal file
40
frontend/src/components/treatment/caseSendLabel.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import type { LinkedOrganizationOption, TreatmentCaseSendInfo } from '@/types/treatment';
|
||||
|
||||
export function formatCaseSentLines(
|
||||
sends: TreatmentCaseSendInfo[] | undefined,
|
||||
fallback?: {
|
||||
organizationIds: string[];
|
||||
sentAt: string | null;
|
||||
orgs?: LinkedOrganizationOption[];
|
||||
},
|
||||
): string[] {
|
||||
if (sends?.length) {
|
||||
return sends.map((s) => {
|
||||
const at = new Date(s.sentAt).toLocaleString();
|
||||
return `Sent to ${s.organizationName} at ${at}`;
|
||||
});
|
||||
}
|
||||
|
||||
if (fallback?.sentAt && fallback.organizationIds.length > 0) {
|
||||
const at = new Date(fallback.sentAt).toLocaleString();
|
||||
const nameById = new Map(fallback.orgs?.map((o) => [o.id, o.name]) ?? []);
|
||||
return fallback.organizationIds.map((id) => {
|
||||
const name = nameById.get(id) ?? 'organization';
|
||||
return `Sent to ${name} at ${at}`;
|
||||
});
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
export function formatCaseSentSummary(
|
||||
sends: TreatmentCaseSendInfo[] | undefined,
|
||||
fallback?: {
|
||||
organizationIds: string[];
|
||||
sentAt: string | null;
|
||||
orgs?: LinkedOrganizationOption[];
|
||||
},
|
||||
): string | null {
|
||||
const lines = formatCaseSentLines(sends, fallback);
|
||||
return lines.length > 0 ? lines.join(' · ') : null;
|
||||
}
|
||||
Reference in New Issue
Block a user