reduce duplicated code
This commit is contained in:
@@ -29,6 +29,7 @@ import { Button } from "@/components/ui/button";
|
|||||||
import { Checkbox } from "@/components/ui/checkbox";
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
import { Separator } from "@/components/ui/separator";
|
import { Separator } from "@/components/ui/separator";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
import { formatDate } from "../lib/dateUtils";
|
||||||
import * as api from "../api";
|
import * as api from "../api";
|
||||||
import { FitAssessment } from ".";
|
import { FitAssessment } from ".";
|
||||||
import type { Job, ResumeProjectCatalogItem } from "../../shared/types";
|
import type { Job, ResumeProjectCatalogItem } from "../../shared/types";
|
||||||
@@ -49,22 +50,6 @@ interface DiscoveredPanelProps {
|
|||||||
// Helpers
|
// Helpers
|
||||||
// ─────────────────────────────────────────────────────────────────────────────
|
// ─────────────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
const formatDate = (dateStr: string | null) => {
|
|
||||||
if (!dateStr) return null;
|
|
||||||
try {
|
|
||||||
const normalized = dateStr.includes("T") ? dateStr : dateStr.replace(" ", "T");
|
|
||||||
const parsed = new Date(normalized);
|
|
||||||
if (Number.isNaN(parsed.getTime())) return dateStr;
|
|
||||||
return parsed.toLocaleDateString("en-GB", {
|
|
||||||
day: "numeric",
|
|
||||||
month: "short",
|
|
||||||
year: "numeric",
|
|
||||||
});
|
|
||||||
} catch {
|
|
||||||
return dateStr;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const stripHtml = (value: string) =>
|
const stripHtml = (value: string) =>
|
||||||
value
|
value
|
||||||
.replace(/<[^>]*>/g, " ")
|
.replace(/<[^>]*>/g, " ")
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
export const formatDate = (dateStr?: string | null) => {
|
||||||
|
if (!dateStr) return null;
|
||||||
|
try {
|
||||||
|
const normalized = dateStr.includes("T") ? dateStr : dateStr.replace(" ", "T");
|
||||||
|
const parsed = new Date(normalized);
|
||||||
|
if (Number.isNaN(parsed.getTime())) return dateStr;
|
||||||
|
return parsed.toLocaleDateString("en-GB", {
|
||||||
|
day: "numeric",
|
||||||
|
month: "short",
|
||||||
|
year: "numeric",
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
return dateStr;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const formatDateTime = (dateStr?: string | null) => {
|
||||||
|
if (!dateStr) return null;
|
||||||
|
try {
|
||||||
|
const normalized = dateStr.includes("T") ? dateStr : dateStr.replace(" ", "T");
|
||||||
|
const parsed = new Date(normalized);
|
||||||
|
if (Number.isNaN(parsed.getTime())) return dateStr;
|
||||||
|
const date = parsed.toLocaleDateString("en-GB", {
|
||||||
|
day: "numeric",
|
||||||
|
month: "short",
|
||||||
|
year: "numeric",
|
||||||
|
});
|
||||||
|
const time = parsed.toLocaleTimeString("en-GB", {
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
});
|
||||||
|
return `${date} ${time}`;
|
||||||
|
} catch {
|
||||||
|
return dateStr;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -60,6 +60,7 @@ import {
|
|||||||
} from "@/components/ui/sheet";
|
} from "@/components/ui/sheet";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { copyTextToClipboard, formatJobForWebhook } from "@client/lib/jobCopy";
|
import { copyTextToClipboard, formatJobForWebhook } from "@client/lib/jobCopy";
|
||||||
|
import { formatDate, formatDateTime } from "../lib/dateUtils";
|
||||||
import { PipelineProgress, DiscoveredPanel, ManualImportSheet } from "../components";
|
import { PipelineProgress, DiscoveredPanel, ManualImportSheet } from "../components";
|
||||||
import { ReadyPanel } from "../components/ReadyPanel";
|
import { ReadyPanel } from "../components/ReadyPanel";
|
||||||
import * as api from "../api";
|
import * as api from "../api";
|
||||||
@@ -155,43 +156,6 @@ const emptyStateCopy: Record<FilterTab, string> = {
|
|||||||
all: "No jobs in the system yet. Run the pipeline to get started.",
|
all: "No jobs in the system yet. Run the pipeline to get started.",
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatDate = (dateStr: string | null) => {
|
|
||||||
if (!dateStr) return null;
|
|
||||||
try {
|
|
||||||
const normalized = dateStr.includes("T") ? dateStr : dateStr.replace(" ", "T");
|
|
||||||
const parsed = new Date(normalized);
|
|
||||||
if (Number.isNaN(parsed.getTime())) return dateStr;
|
|
||||||
return parsed.toLocaleDateString("en-GB", {
|
|
||||||
day: "numeric",
|
|
||||||
month: "short",
|
|
||||||
year: "numeric",
|
|
||||||
});
|
|
||||||
} catch {
|
|
||||||
return dateStr;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const formatDateTime = (dateStr: string | null) => {
|
|
||||||
if (!dateStr) return null;
|
|
||||||
try {
|
|
||||||
const normalized = dateStr.includes("T") ? dateStr : dateStr.replace(" ", "T");
|
|
||||||
const parsed = new Date(normalized);
|
|
||||||
if (Number.isNaN(parsed.getTime())) return dateStr;
|
|
||||||
const date = parsed.toLocaleDateString("en-GB", {
|
|
||||||
day: "numeric",
|
|
||||||
month: "short",
|
|
||||||
year: "numeric",
|
|
||||||
});
|
|
||||||
const time = parsed.toLocaleTimeString("en-GB", {
|
|
||||||
hour: "2-digit",
|
|
||||||
minute: "2-digit",
|
|
||||||
});
|
|
||||||
return `${date} ${time}`;
|
|
||||||
} catch {
|
|
||||||
return dateStr;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const safeFilenamePart = (value: string) => value.replace(/[^a-z0-9]/gi, "_");
|
const safeFilenamePart = (value: string) => value.replace(/[^a-z0-9]/gi, "_");
|
||||||
|
|
||||||
const dateValue = (value: string | null) => {
|
const dateValue = (value: string | null) => {
|
||||||
|
|||||||
@@ -38,46 +38,10 @@ import {
|
|||||||
SheetTrigger,
|
SheetTrigger,
|
||||||
} from "@/components/ui/sheet";
|
} from "@/components/ui/sheet";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
import { formatDate, formatDateTime } from "../lib/dateUtils";
|
||||||
import * as api from "../api";
|
import * as api from "../api";
|
||||||
import type { CreateJobInput } from "../../shared/types";
|
import type { CreateJobInput } from "../../shared/types";
|
||||||
|
|
||||||
const formatDate = (dateStr?: string | null) => {
|
|
||||||
if (!dateStr) return null;
|
|
||||||
try {
|
|
||||||
const normalized = dateStr.includes("T") ? dateStr : dateStr.replace(" ", "T");
|
|
||||||
const parsed = new Date(normalized);
|
|
||||||
if (Number.isNaN(parsed.getTime())) return dateStr;
|
|
||||||
return parsed.toLocaleDateString("en-GB", {
|
|
||||||
day: "numeric",
|
|
||||||
month: "short",
|
|
||||||
year: "numeric",
|
|
||||||
});
|
|
||||||
} catch {
|
|
||||||
return dateStr;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const formatDateTime = (dateStr?: string | null) => {
|
|
||||||
if (!dateStr) return null;
|
|
||||||
try {
|
|
||||||
const normalized = dateStr.includes("T") ? dateStr : dateStr.replace(" ", "T");
|
|
||||||
const parsed = new Date(normalized);
|
|
||||||
if (Number.isNaN(parsed.getTime())) return dateStr;
|
|
||||||
const date = parsed.toLocaleDateString("en-GB", {
|
|
||||||
day: "numeric",
|
|
||||||
month: "short",
|
|
||||||
year: "numeric",
|
|
||||||
});
|
|
||||||
const time = parsed.toLocaleTimeString("en-GB", {
|
|
||||||
hour: "2-digit",
|
|
||||||
minute: "2-digit",
|
|
||||||
});
|
|
||||||
return `${date} ${time}`;
|
|
||||||
} catch {
|
|
||||||
return dateStr;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const stripHtml = (value: string) => value.replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
|
const stripHtml = (value: string) => value.replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
|
||||||
|
|
||||||
const clampText = (value: string, max = 160) => (value.length > max ? `${value.slice(0, max).trim()}...` : value);
|
const clampText = (value: string, max = 160) => (value.length > max ? `${value.slice(0, max).trim()}...` : value);
|
||||||
|
|||||||
Reference in New Issue
Block a user