--
This commit is contained in:
+25
-6
@@ -1,4 +1,4 @@
|
||||
import type { DcrStatus, Role } from "../types";
|
||||
import type { DcrStatus, ReportType, Role } from "../types";
|
||||
|
||||
export const STATUS_LABEL: Record<DcrStatus, string> = {
|
||||
DRAFT: "Draft",
|
||||
@@ -7,16 +7,28 @@ export const STATUS_LABEL: Record<DcrStatus, string> = {
|
||||
APPROVED: "Approved",
|
||||
};
|
||||
|
||||
export const REPORT_TYPE_LABEL: Record<ReportType, string> = { PLAN: "Daily Call Report (Plan)", ACTUAL: "Daily Call Report (Done)", SELF: "Daily Call Report (Self)" };
|
||||
/** Short form for badges and tight spaces. */
|
||||
export const REPORT_TYPE_SHORT: Record<ReportType, string> = { PLAN: "Plan", ACTUAL: "Done", SELF: "Self" };
|
||||
/** An Area Manager's own report has no approval: once submitted it is final. */
|
||||
export const statusLabel = (status: DcrStatus, type?: ReportType) => (type === "SELF" && status === "APPROVED" ? "Submitted" : STATUS_LABEL[status]);
|
||||
|
||||
/** The roles that do field work and file reports: an SFE does an MR's work. */
|
||||
export const isField = (role: string): boolean => role === "MR" || role === "SFE";
|
||||
|
||||
export const ROLE_LABEL: Record<Role, string> = {
|
||||
MR: "Medical Representative",
|
||||
SFE: "Senior Field Executive",
|
||||
AM: "Area Manager",
|
||||
GM: "General Manager",
|
||||
ADMIN: "Administrator",
|
||||
};
|
||||
|
||||
/** Today's date in the user's own timezone (toISOString would give the UTC date). */
|
||||
export const todayISO = () => {
|
||||
/** Today's local date as YYYY-MM-DD, or `days` from today. */
|
||||
export const todayISO = (days = 0) => {
|
||||
const d = new Date();
|
||||
d.setDate(d.getDate() + days);
|
||||
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
||||
};
|
||||
|
||||
@@ -52,10 +64,17 @@ export const humanize = (key: string) =>
|
||||
.map((word) => (ACRONYMS.has(word) ? word.toUpperCase() : word.charAt(0).toUpperCase() + word.slice(1)))
|
||||
.join(" ");
|
||||
|
||||
/** Column labels that read wrong once spelled out from their key. The stored column is still
|
||||
* "aug_sales" (the printed form's own field, matching the database and the PDF) — this is only
|
||||
* what the app displays, since "Aug Sales" is misleading once the row can be any month. */
|
||||
const COLUMN_LABEL_OVERRIDES: Record<string, string> = { aug_sales: "Month Sales" };
|
||||
/** Column labels that read wrong once spelled out from their key; the stored column keeps its name. */
|
||||
const COLUMN_LABEL_OVERRIDES: Record<string, string> = {
|
||||
kilometers_km: "Kilometers KM (One Way)",
|
||||
fare: "Fare (Rs)",
|
||||
da_hq: "Daily allowance – H.Q. (Rs)",
|
||||
da_ex: "Daily allowance – EX (Rs)",
|
||||
da_out: "Daily allowance – OUT (Rs)",
|
||||
postage: "Postage (Rs)",
|
||||
other_expense: "Other expense (Rs)",
|
||||
total: "Total (Rs)",
|
||||
};
|
||||
export const columnLabel = (key: string) => COLUMN_LABEL_OVERRIDES[key] ?? humanize(key);
|
||||
|
||||
export const errorMessage = (error: unknown, fallback = "Something went wrong") =>
|
||||
|
||||
@@ -1,11 +1,26 @@
|
||||
import { isField } from "./format";
|
||||
import type { AreaManagerMapping, Headquarters, User } from "../types";
|
||||
|
||||
/** Headquarters a person works in: an MR has one, an AM has any number, GM and Admin cover all. */
|
||||
export function headquartersOf(user: User, hqs: Headquarters[], mappings: AreaManagerMapping[]): { all: boolean; items: Headquarters[] } {
|
||||
if (user.role === "GM" || user.role === "ADMIN") return { all: true, items: [] };
|
||||
const ids = user.role === "MR"
|
||||
? (user.headquarters_id ? [user.headquarters_id] : [])
|
||||
const ids = isField(user.role)
|
||||
? [...(user.headquarters_id ? [user.headquarters_id] : []), ...(user.extra_headquarter_ids ?? [])]
|
||||
: mappings.filter((m) => m.area_manager_user_id === user.id).map((m) => m.headquarters_id);
|
||||
const wanted = new Set(ids);
|
||||
return { all: false, items: hqs.filter((h) => wanted.has(h.id)) };
|
||||
}
|
||||
|
||||
/**
|
||||
* The Area Managers of each headquarters, by name ("Asha Rao, Ravi Das"). A headquarters may
|
||||
* have several. `except` leaves one Area Manager out, e.g. the one whose headquarters are being edited.
|
||||
*/
|
||||
export function areaManagersOf(mappings: AreaManagerMapping[], users: User[], except?: string): Record<string, string> {
|
||||
const name = new Map(users.map((u) => [u.id, u.full_name]));
|
||||
const byHq = new Map<string, string[]>();
|
||||
for (const m of mappings) {
|
||||
if (m.area_manager_user_id === except) continue;
|
||||
byHq.set(m.headquarters_id, [...(byHq.get(m.headquarters_id) ?? []), name.get(m.area_manager_user_id) ?? "an Area Manager"]);
|
||||
}
|
||||
return Object.fromEntries([...byHq].map(([hq, names]) => [hq, names.sort().join(", ")]));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { IconName } from "../components/ui/Icon";
|
||||
import type { Role } from "../types";
|
||||
import type { ReportType, Role } from "../types";
|
||||
|
||||
export interface NavItem {
|
||||
to: string;
|
||||
@@ -13,13 +13,20 @@ export interface NavSection {
|
||||
items: NavItem[];
|
||||
}
|
||||
|
||||
/** Each report type has its own list, so the sidebar highlights the right one on a report's page. */
|
||||
const REPORTS_PATH: Record<ReportType, string> = { PLAN: "/reports/plan", ACTUAL: "/reports/done", SELF: "/reports/self" };
|
||||
export const reportsPath = (type: ReportType) => REPORTS_PATH[type];
|
||||
export const reportPath = (report: { id: string; report_type: ReportType }) => `${reportsPath(report.report_type)}/${report.id}`;
|
||||
|
||||
/** Sidebar structure. `roles` limits an item to those roles; omitted means everyone. */
|
||||
export const NAVIGATION: NavSection[] = [
|
||||
{
|
||||
title: "Workspace",
|
||||
items: [
|
||||
{ to: "/", label: "Dashboard", icon: "dashboard" },
|
||||
{ to: "/reports", label: "Daily Call Reports", icon: "file", roles: ["MR", "AM", "GM"] },
|
||||
{ to: "/reports/plan", label: "Daily Call Report (Plan)", icon: "file", roles: ["MR", "SFE", "AM", "GM"] },
|
||||
{ to: "/reports/done", label: "Daily Call Report (Done)", icon: "checkCircle", roles: ["MR", "SFE", "AM", "GM"] },
|
||||
{ to: "/reports/self", label: "Daily Call Report (Self)", icon: "file", roles: ["AM", "GM"] },
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -27,13 +34,13 @@ export const NAVIGATION: NavSection[] = [
|
||||
items: [
|
||||
{ to: "/directory", label: "Doctors & Chemists", icon: "stethoscope" },
|
||||
{ to: "/products", label: "Products", icon: "box" },
|
||||
{ to: "/forms", label: "Company forms", icon: "table", roles: ["MR", "AM", "ADMIN"] },
|
||||
{ to: "/forms", label: "Company forms", icon: "table", roles: ["MR", "SFE", "AM", "GM", "ADMIN"] },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Administration",
|
||||
items: [
|
||||
{ to: "/admin", label: "Setup", icon: "settings", roles: ["ADMIN"] },
|
||||
{ to: "/admin", label: "Setup", icon: "settings", roles: ["ADMIN", "MR", "SFE"] },
|
||||
{ to: "/users", label: "Users", icon: "users", roles: ["ADMIN", "GM"] },
|
||||
],
|
||||
},
|
||||
@@ -49,9 +56,9 @@ export function navigationFor(role: Role): NavSection[] {
|
||||
/** Title shown in the top bar for the current path. */
|
||||
export function titleFor(path: string): string {
|
||||
if (path === "/") return "Dashboard";
|
||||
if (path === "/reports/new") return "New report";
|
||||
if (path.startsWith("/reports/")) return "Report";
|
||||
if (path.startsWith("/reports")) return "Daily Call Reports";
|
||||
if (path.startsWith("/reports/done")) return "Daily Call Report (Done)";
|
||||
if (path.startsWith("/reports/self")) return "Daily Call Report (Self)";
|
||||
if (path.startsWith("/reports")) return "Daily Call Report (Plan)";
|
||||
if (path.startsWith("/forms")) return "Company forms";
|
||||
if (path.startsWith("/directory")) return "Doctors & Chemists";
|
||||
if (path.startsWith("/products")) return "Products";
|
||||
|
||||
Reference in New Issue
Block a user