Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

Add jobs mock data & allow local icons for companies

Khuram Niazaa566be71c38
diff --git a/src/actions/company.actions.ts b/src/actions/company.actions.ts
index b0ace96..b1c50a3 100644
--- a/src/actions/company.actions.ts
+++ b/src/actions/company.actions.ts
@@ -87,9 +87,9 @@ export const getAllCompanies = async (): Promise<any | undefined> => {
const isValidImageUrl = (url: string): boolean => {
if (!url) return true;
+ if (url.startsWith("/")) return true;
try {
const urlObj = new URL(url);
- // Only allow http and https protocols
if (!["http:", "https:"].includes(urlObj.protocol)) {
return false;
}
diff --git a/src/actions/mock.actions.ts b/src/actions/mock.actions.ts
index 39736f5..bdae7e4 100644
--- a/src/actions/mock.actions.ts
+++ b/src/actions/mock.actions.ts
@@ -14,7 +14,14 @@ import {
mockResumePeople,
MOCK_VALUE_PREFIX,
} from "@/lib/data/mockProfileData";
-import { subYears } from "date-fns";
+import { subYears, subDays } from "date-fns";
+import { getRandomInt } from "@/lib/mock.utils";
+import {
+ mockJobDescriptions,
+ mockSalaryRanges,
+ mockJobTypes,
+ STATUS_WEIGHTS,
+} from "@/lib/data/mockJobsData";
export const generateMockActivitiesAction = async (): Promise<any> => {
try {
@@ -441,3 +448,189 @@ export const clearMockProfileDataAction = async (): Promise<any> => {
return handleError(error, "Failed to clear mock profile data");
}
};
+
+function pickWeightedStatus(statusMap: Map<string, string>): string {
+ const roll = Math.random() * 100;
+ let cumulative = 0;
+ for (const { value, weight } of STATUS_WEIGHTS) {
+ cumulative += weight;
+ if (roll < cumulative) {
+ const id = statusMap.get(value);
+ if (id) return id;
+ }
+ }
+ return statusMap.values().next().value!;
+}
+
+export const generateMockJobsAction = async (): Promise<any> => {
+ try {
+ const user = await getCurrentUser();
+ if (!user) throw new Error("Not authenticated");
+
+ if (process.env.NODE_ENV !== "development") {
+ throw new Error(
+ "Mock data generation is only available in development mode",
+ );
+ }
+
+ // Check for mock profile data
+ const mockCompanyCount = await prisma.company.count({
+ where: { value: { startsWith: MOCK_VALUE_PREFIX }, createdBy: user.id },
+ });
+ if (mockCompanyCount === 0) {
+ return {
+ success: false,
+ message:
+ "Please generate mock profile data first (companies, locations, job titles, and resumes are required).",
+ };
+ }
+
+ // Fetch mock reference data
+ const [companies, locations, jobTitles, statuses, resumes] =
+ await Promise.all([
+ prisma.company.findMany({
+ where: {
+ value: { startsWith: MOCK_VALUE_PREFIX },
+ createdBy: user.id,
+ },
+ }),
+ prisma.location.findMany({
+ where: {
+ value: { startsWith: MOCK_VALUE_PREFIX },
+ createdBy: user.id,
+ },
+ }),
+ prisma.jobTitle.findMany({
+ where: {
+ value: { startsWith: MOCK_VALUE_PREFIX },
+ createdBy: user.id,
+ },
+ }),
+ prisma.jobStatus.findMany(),
+ prisma.resume.findMany({
+ where: {
+ title: { contains: "[MOCK_DATA]" },
+ profile: { userId: user.id },
+ },
+ }),
+ ]);
+
+ if (statuses.length === 0) {
+ return { success: false, message: "No job statuses found in database." };
+ }
+
+ const statusMap = new Map(statuses.map((s) => [s.value, s.id]));
+ const totalJobs = getRandomInt(30, 40);
+ const now = new Date();
+
+ const jobsData = Array.from({ length: totalJobs }, () => {
+ const company = companies[getRandomInt(0, companies.length - 1)];
+ const jobTitle = jobTitles[getRandomInt(0, jobTitles.length - 1)];
+ const location = locations[getRandomInt(0, locations.length - 1)];
+ const statusId = pickWeightedStatus(statusMap);
+ const statusValue =
+ statuses.find((s) => s.id === statusId)?.value ?? "draft";
+
+ const daysAgo = getRandomInt(0, 30);
+ const createdAt = subDays(now, daysAgo);
+
+ const isApplied = ["applied", "interview", "offer", "rejected"].includes(
+ statusValue,
+ );
+ const appliedDate = isApplied
+ ? subDays(now, Math.max(0, daysAgo - getRandomInt(0, 2)))
+ : null;
+
+ const description =
+ mockJobDescriptions[getRandomInt(0, mockJobDescriptions.length - 1)];
+ const hasSalary = Math.random() < 0.5;
+ const salaryRange = hasSalary
+ ? mockSalaryRanges[getRandomInt(0, mockSalaryRanges.length - 1)]
+ : null;
+ const jobType = mockJobTypes[getRandomInt(0, mockJobTypes.length - 1)];
+
+ // ~80% of jobs link to a resume
+ const resume =
+ resumes.length > 0 && Math.random() < 0.8
+ ? resumes[getRandomInt(0, resumes.length - 1)]
+ : null;
+
+ return {
+ userId: user.id,
+ companyId: company.id,
+ jobTitleId: jobTitle.id,
+ locationId: location.id,
+ statusId,
+ createdAt,
+ applied: isApplied,
+ appliedDate,
+ description: `${description} ${MOCK_DATA_IDENTIFIER}`,
+ jobType,
+ salaryRange,
+ resumeId: resume?.id ?? null,
+ };
+ });
+
+ const created = await prisma.job.createMany({ data: jobsData });
+
+ return {
+ success: true,
+ message: `Generated ${created.count} mock jobs across the last 30 days.`,
+ };
+ } catch (error) {
+ return handleError(error, "Failed to generate mock jobs");
+ }
+};
+
+export const clearMockJobsAction = async (): Promise<any> => {
+ try {
+ const user = await getCurrentUser();
+ if (!user) throw new Error("Not authenticated");
+
+ if (process.env.NODE_ENV !== "development") {
+ throw new Error(
+ "Mock data clearing is only available in development mode",
+ );
+ }
+
+ // Find mock jobs
+ const mockJobs = await prisma.job.findMany({
+ where: {
+ userId: user.id,
+ description: { contains: MOCK_DATA_IDENTIFIER },
+ },
+ select: { id: true },
+ });
+
+ const jobIds = mockJobs.map((j) => j.id);
+
+ if (jobIds.length === 0) {
+ return { success: true, message: "No mock jobs found to delete." };
+ }
+
+ // Delete related records first (FK constraints)
+ await prisma.note.deleteMany({ where: { jobId: { in: jobIds } } });
+ await prisma.interview.deleteMany({ where: { jobId: { in: jobIds } } });
+
+ // Disconnect tags (M2M)
+ await Promise.all(
+ jobIds.map((id) =>
+ prisma.job.update({
+ where: { id },
+ data: { tags: { set: [] } },
+ }),
+ ),
+ );
+
+ const deleteResult = await prisma.job.deleteMany({
+ where: { id: { in: jobIds } },
+ });
+
+ return {
+ success: true,
+ message: `Deleted ${deleteResult.count} mock jobs.`,
+ };
+ } catch (error) {
+ return handleError(error, "Failed to clear mock jobs");
+ }
+};
diff --git a/src/app/dashboard/developer/page.tsx b/src/app/dashboard/developer/page.tsx
index 1af8bd8..de5e7e0 100644
--- a/src/app/dashboard/developer/page.tsx
+++ b/src/app/dashboard/developer/page.tsx
@@ -2,6 +2,7 @@ import { Metadata } from "next";
import {
MockActivitiesCard,
MockProfileCard,
+ MockJobsCard,
} from "@/components/developer/DeveloperContainer";
export const metadata: Metadata = {
@@ -24,6 +25,9 @@ export default function DeveloperPage() {
<div className="col-start-2 self-start">
<MockProfileCard />
</div>
+ <div className="col-start-3 self-start">
+ <MockJobsCard />
+ </div>
</>
);
}
diff --git a/src/components/developer/DeveloperContainer.tsx b/src/components/developer/DeveloperContainer.tsx
index 71d2d2a..3bcd0e4 100644
--- a/src/components/developer/DeveloperContainer.tsx
+++ b/src/components/developer/DeveloperContainer.tsx
@@ -14,6 +14,8 @@ import {
clearMockActivitiesAction,
generateMockProfileDataAction,
clearMockProfileDataAction,
+ generateMockJobsAction,
+ clearMockJobsAction,
} from "@/actions/mock.actions";
type StatusMessage = { type: "success" | "error"; text: string };
@@ -233,3 +235,99 @@ export function MockProfileCard() {
</div>
);
}
+
+export function MockJobsCard() {
+ const [isGenerating, setIsGenerating] = useState(false);
+ const [isClearing, setIsClearing] = useState(false);
+ const [message, setMessage] = useState<StatusMessage | null>(null);
+
+ const handleGenerate = async () => {
+ setIsGenerating(true);
+ setMessage(null);
+ const result = await generateMockJobsAction();
+ setMessage({
+ type: result.success ? "success" : "error",
+ text:
+ result.message ||
+ (result.success
+ ? "Mock jobs generated successfully"
+ : "Failed to generate mock jobs"),
+ });
+ setIsGenerating(false);
+ };
+
+ const handleClear = async () => {
+ if (
+ !confirm(
+ "Are you sure you want to delete all mock jobs? This action cannot be undone.",
+ )
+ )
+ return;
+
+ setIsClearing(true);
+ setMessage(null);
+ const result = await clearMockJobsAction();
+ setMessage({
+ type: result.success ? "success" : "error",
+ text:
+ result.message ||
+ (result.success
+ ? "Mock jobs cleared successfully"
+ : "Failed to clear mock jobs"),
+ });
+ setIsClearing(false);
+ };
+
+ return (
+ <div className="space-y-4">
+ {message && <StatusBanner message={message} />}
+ <Card>
+ <CardHeader>
+ <CardTitle>Mock Jobs Data</CardTitle>
+ <CardDescription>
+ Generate or clear mock jobs for testing
+ </CardDescription>
+ </CardHeader>
+ <CardContent className="space-y-4">
+ <div>
+ <h3 className="font-semibold mb-2">Generate Mock Jobs</h3>
+ <p className="text-sm text-muted-foreground mb-4">
+ Creates 30-40 mock jobs spread across the last 30 days using mock
+ profile data (companies, locations, job titles, resumes). Status
+ distribution is realistic: mostly Applied/Rejected, some
+ Interviews, few Offers. Requires mock profile data to be generated
+ first.
+ </p>
+ <Button
+ onClick={handleGenerate}
+ disabled={isGenerating || isClearing}
+ className="w-full"
+ >
+ {isGenerating && (
+ <Loader2 className="mr-2 h-4 w-4 animate-spin" />
+ )}
+ {isGenerating ? "Generating..." : "Generate Mock Jobs"}
+ </Button>
+ </div>
+
+ <div className="border-t pt-4">
+ <h3 className="font-semibold mb-2">Clear Mock Jobs</h3>
+ <p className="text-sm text-muted-foreground mb-4">
+ Deletes only mock jobs (marked with [MOCK_DATA] identifier).
+ Regular jobs are not affected.
+ </p>
+ <Button
+ onClick={handleClear}
+ disabled={isClearing || isGenerating}
+ variant="destructive"
+ className="w-full"
+ >
+ {isClearing && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
+ {isClearing ? "Clearing..." : "Clear Mock Jobs"}
+ </Button>
+ </div>
+ </CardContent>
+ </Card>
+ </div>
+ );
+}
diff --git a/src/lib/data/mockJobsData.ts b/src/lib/data/mockJobsData.ts
new file mode 100644
index 0000000..dac2b19
--- /dev/null
+++ b/src/lib/data/mockJobsData.ts
@@ -0,0 +1,51 @@
+import { MOCK_DATA_IDENTIFIER } from "@/lib/data/mockActivities";
+
+export { MOCK_DATA_IDENTIFIER };
+
+export const mockJobDescriptions = [
+ "We are looking for a talented engineer to join our team and help build scalable, high-performance web applications. You will work closely with product and design teams to deliver features that delight our users.",
+ "Join our engineering team to design and implement robust backend services. You'll work with distributed systems, databases, and APIs to power our platform's core functionality.",
+ "We're seeking a developer passionate about creating beautiful, responsive user interfaces. You'll collaborate with designers and backend engineers to build seamless user experiences across web and mobile.",
+ "Help us build and maintain our cloud infrastructure. You'll work with containerization, CI/CD pipelines, and monitoring systems to ensure our platform is reliable and performant.",
+ "We need an engineer to help us scale our data pipeline and analytics platform. You'll work with large datasets, streaming systems, and machine learning models to drive insights.",
+ "Join our team to build next-generation developer tools and internal platforms. You'll improve engineering productivity and create tools that other teams rely on daily.",
+ "We're looking for someone to help modernize our legacy systems. You'll work on migrating services to modern architectures while ensuring zero downtime and backward compatibility.",
+ "Help us build secure, compliant systems that handle sensitive user data. You'll work with authentication, authorization, encryption, and audit logging across our platform.",
+ "Join our growth engineering team to build and optimize user acquisition and onboarding flows. You'll run experiments, analyze results, and ship features that drive key metrics.",
+ "We need an engineer to help build our real-time collaboration features. You'll work with WebSockets, conflict resolution algorithms, and state synchronization across clients.",
+ "We're seeking a full-stack engineer to own features end-to-end, from database schema design to pixel-perfect UI implementation. You'll have significant autonomy and impact.",
+ "Join our platform team to build shared services and libraries used by dozens of engineering teams. You'll design APIs, write documentation, and support internal customers.",
+];
+
+export const mockSalaryRanges = [
+ "$80k - $110k",
+ "$90k - $130k",
+ "$100k - $140k",
+ "$110k - $150k",
+ "$120k - $160k",
+ "$130k - $170k",
+ "$140k - $180k",
+ "$150k - $200k",
+ "$160k - $220k",
+ "$180k - $250k",
+];
+
+export const mockJobTypes = [
+ "Full-time",
+ "Full-time",
+ "Full-time",
+ "Contract",
+ "Remote",
+ "Hybrid",
+];
+
+// Weighted status distribution — values are cumulative thresholds out of 100
+export const STATUS_WEIGHTS: { value: string; weight: number }[] = [
+ { value: "applied", weight: 35 },
+ { value: "rejected", weight: 25 },
+ { value: "interview", weight: 20 },
+ { value: "draft", weight: 10 },
+ { value: "offer", weight: 5 },
+ { value: "expired", weight: 3 },
+ { value: "archived", weight: 2 },
+];
diff --git a/src/models/addCompanyForm.schema.ts b/src/models/addCompanyForm.schema.ts
index 90efd6f..2d29d6a 100644
--- a/src/models/addCompanyForm.schema.ts
+++ b/src/models/addCompanyForm.schema.ts
@@ -22,7 +22,7 @@ export const AddCompanyFormSchema = z.object({
.default("")
.optional()
.refine(
- (url) => !url || isValidUrl(url),
- "Please enter a valid URL (e.g., https://example.com/logo.png)",
+ (url) => !url || url.startsWith("/") || isValidUrl(url),
+ "Please enter a valid URL (e.g., https://example.com/logo.png or /icons/logo.svg)",
),
});