Files
job-tracker/web/src/stores/jobApplications.js
T
adamf 1147bc5697
Test and publish / test (push) Successful in 2m33s
Test and publish / publish (push) Successful in 11m9s
Add application workflow and lead analytics
2026-10-23 20:45:48 +01:00

63 lines
2.3 KiB
JavaScript

/**
* Job applications for the tracker at /jobs/ — CRUD built on
* createCrudStore(), plus the on-demand posting text.
*
* Admin-only on the server, and only that one page uses it, so nothing fetches
* it until the view mounts.
*/
import { createCrudStore } from "@/stores/createCrudStore";
import { gql } from "@/graphql";
// `description` is deliberately not here: it is the full text of the posting,
// tens of kilobytes a row, and is fetched per row when asked for.
const APP_FIELDS = `id jobTitle company location url status notes appliedAt createdAt updatedAt nextAction nextActionAt contactName contactEmail contactRole salaryRange workArrangement applicationSource resumeVersion requisitionId`;
export const useJobApplicationsStore = createCrudStore("jobApplications", {
type: "JobApplication",
list: "jobApplications",
itemsKey: "applications",
fields: APP_FIELDS,
insert: "prepend",
// deleteJobApplication returns Boolean!, and errors for an id that is gone.
deleteReturns: "boolean",
extend: ({ update }) => ({
/**
* The captured posting text for one row; `""` when none was saved. Throws
* on failure. Not cached here: the view keeps its own per-visit cache, so
* returning to the page re-reads a posting the userscript may have
* replaced.
*/
async fetchDescription(id) {
const data = await gql(
`query JobDescription($id: ID!) { jobApplication(id: $id) { description } }`,
{ id },
);
return data.jobApplication?.description ?? "";
},
async fetchActivity(id) {
const data = await gql(
`query JobApplicationActivity($id: ID!) {
jobApplicationEvents(applicationId: $id) { id kind note occurredAt createdAt }
}`,
{ id },
);
return data.jobApplicationEvents ?? [];
},
async updateFollowUp(id, input) {
return update(id, input);
},
async addActivityEvent(applicationId, input) {
const data = await gql(
`mutation AddJobApplicationEvent($applicationId: ID!, $input: AddJobApplicationEventInput!) {
addJobApplicationEvent(applicationId: $applicationId, input: $input) {
id kind note occurredAt createdAt
}
}`,
{ applicationId, input },
);
return data.addJobApplicationEvent;
},
}),
});