feat: add candidate profile, questionnaire and company forms
This commit is contained in:
1 parent
3a61a8e8bb
commit
f81cd0ae09
68 files changed
+9517
-54
No files matched your search
@@ -0,0 +1,28 @@
|
||||
export {
|
||||
addExperience,
|
||||
addRole,
|
||||
addSoftSkill,
|
||||
addStack,
|
||||
buildCandidateProfileUpdate,
|
||||
mapProfileServerErrors,
|
||||
moveExperience,
|
||||
profilePointerField,
|
||||
removeExperience,
|
||||
removeItem,
|
||||
reviewExperienceOverlaps,
|
||||
setParallelAcknowledgement,
|
||||
toCandidateProfileDraft,
|
||||
updateExperienceDraft,
|
||||
updateFieldDraft,
|
||||
updateRoleDraft,
|
||||
updateSalaryDraft,
|
||||
updateSoftSkillDraft,
|
||||
updateStackDraft,
|
||||
type CandidateProfileDraft,
|
||||
type ExperienceDraft,
|
||||
type FieldDraft,
|
||||
type ProfileFormIssue,
|
||||
type RoleDraft,
|
||||
type SoftSkillDraft,
|
||||
type StackDraft,
|
||||
} from "./model/profile-form";
|
||||
@@ -0,0 +1,234 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { CandidateProfile } from "../../../shared/api/schemas";
|
||||
import {
|
||||
addExperience,
|
||||
buildCandidateProfileUpdate,
|
||||
mapProfileServerErrors,
|
||||
moveExperience,
|
||||
reviewExperienceOverlaps,
|
||||
setParallelAcknowledgement,
|
||||
toCandidateProfileDraft,
|
||||
updateExperienceDraft,
|
||||
updateFieldDraft,
|
||||
} from "./profile-form";
|
||||
|
||||
const unknownClaim = { status: "unknown", value: null, source: null } as const;
|
||||
|
||||
function blankProfile(): CandidateProfile {
|
||||
return {
|
||||
version: 0,
|
||||
full_name: unknownClaim,
|
||||
contacts: { email: unknownClaim, phone: unknownClaim, telegram: unknownClaim },
|
||||
stack: [],
|
||||
roles: [],
|
||||
experience: [],
|
||||
experience_overlaps: [],
|
||||
soft_skills: [],
|
||||
terms: {
|
||||
location: unknownClaim,
|
||||
relocation: unknownClaim,
|
||||
salary_minimum: unknownClaim,
|
||||
},
|
||||
confirmed_categories: [],
|
||||
updated_at: null,
|
||||
};
|
||||
}
|
||||
|
||||
const suggestion = {
|
||||
origin: "extracted_from_resume",
|
||||
trust_level: 0,
|
||||
quote: "Работал с Go и PostgreSQL",
|
||||
extraction_version: "resume-rules.2026-10.1",
|
||||
confirmed_at: null,
|
||||
} as const;
|
||||
|
||||
describe("candidate profile draft mapping", () => {
|
||||
it("sends an empty first profile as unknown values at version zero", () => {
|
||||
const draft = toCandidateProfileDraft(blankProfile());
|
||||
const result = buildCandidateProfileUpdate(draft, new Date("2026-06-15T00:00:00Z"));
|
||||
|
||||
expect(result.issues).toEqual([]);
|
||||
expect(result.data).toMatchObject({
|
||||
expected_version: 0,
|
||||
full_name: null,
|
||||
contacts: { email: null, phone: null, telegram: null },
|
||||
stack: [],
|
||||
roles: [],
|
||||
experience: [],
|
||||
confirmed_parallel_periods: [],
|
||||
soft_skills: [],
|
||||
terms: { location: null, relocation: null, salary_minimum: null },
|
||||
});
|
||||
expect(result.data).not.toHaveProperty("confirmed_categories");
|
||||
});
|
||||
|
||||
it("preserves untouched suggestions and confirms a changed suggestion", () => {
|
||||
const profile: CandidateProfile = {
|
||||
...blankProfile(),
|
||||
version: 4,
|
||||
full_name: { status: "extracted", value: "Анна Соколова", source: suggestion },
|
||||
contacts: {
|
||||
email: unknownClaim,
|
||||
phone: { status: "extracted", value: "+79000000000", source: suggestion },
|
||||
telegram: unknownClaim,
|
||||
},
|
||||
stack: [{ tag: "Go", status: "extracted", source: suggestion }],
|
||||
experience: [
|
||||
{
|
||||
employer_name: "ООО Пример",
|
||||
specialization: "backend",
|
||||
started_on: "2022-01",
|
||||
ended_on: null,
|
||||
summary: "Разработка сервисов",
|
||||
status: "extracted",
|
||||
source: suggestion,
|
||||
},
|
||||
],
|
||||
soft_skills: [{ skill: "Наставничество", status: "extracted", source: suggestion }],
|
||||
terms: {
|
||||
location: { status: "extracted", value: "Казань", source: suggestion },
|
||||
relocation: unknownClaim,
|
||||
salary_minimum: unknownClaim,
|
||||
},
|
||||
};
|
||||
let draft = toCandidateProfileDraft(profile);
|
||||
const stackId = draft.stack[0]?.id;
|
||||
if (!stackId) throw new Error("Expected a stack suggestion in the fixture.");
|
||||
|
||||
let result = buildCandidateProfileUpdate(draft, new Date("2026-06-15T00:00:00Z"));
|
||||
expect(result.data?.full_name).toEqual({ value: "Анна Соколова", status: "extracted" });
|
||||
expect(result.data?.contacts.phone).toEqual({ value: "+79000000000", status: "extracted" });
|
||||
expect(result.data?.stack).toEqual([{ tag: "Go", status: "extracted" }]);
|
||||
expect(result.data?.experience[0]?.status).toBe("extracted");
|
||||
expect(result.data?.soft_skills).toEqual([{ skill: "Наставничество", status: "extracted" }]);
|
||||
expect(result.data?.terms.location).toEqual({ value: "Казань", status: "extracted" });
|
||||
|
||||
draft = {
|
||||
...draft,
|
||||
stack: draft.stack.map((item) =>
|
||||
item.id === stackId ? { ...item, tag: "Go и PostgreSQL", status: "confirmed" } : item,
|
||||
),
|
||||
};
|
||||
result = buildCandidateProfileUpdate(draft, new Date("2026-06-15T00:00:00Z"));
|
||||
expect(result.data?.stack).toEqual([{ tag: "Go и PostgreSQL", status: "confirmed" }]);
|
||||
|
||||
const nameDraft = toCandidateProfileDraft(profile).fullName;
|
||||
expect(updateFieldDraft(nameDraft, "Новое имя").status).toBe("confirmed");
|
||||
expect(updateFieldDraft(nameDraft, "Анна Соколова").status).toBe("extracted");
|
||||
});
|
||||
|
||||
it("requires an explicit range-bound acknowledgement and clears it after date edits or reorder", () => {
|
||||
let draft = toCandidateProfileDraft(blankProfile());
|
||||
draft = addExperience(draft, "first");
|
||||
draft = updateExperienceDraft(draft, "first", {
|
||||
employer_name: "Первая компания",
|
||||
specialization: "backend",
|
||||
started_on: "2023-01",
|
||||
ended_on: "2024-12",
|
||||
});
|
||||
draft = addExperience(draft, "second");
|
||||
draft = updateExperienceDraft(draft, "second", {
|
||||
employer_name: "Вторая компания",
|
||||
specialization: "frontend",
|
||||
started_on: "2024-01",
|
||||
ended_on: "2025-01",
|
||||
});
|
||||
|
||||
const overlap = reviewExperienceOverlaps(draft, new Date("2026-06-15T00:00:00Z"))[0];
|
||||
expect(overlap).toMatchObject({
|
||||
key: "0:1",
|
||||
requiresAcknowledgement: true,
|
||||
acknowledged: false,
|
||||
});
|
||||
expect(buildCandidateProfileUpdate(draft, new Date("2026-06-15T00:00:00Z")).data).toBeNull();
|
||||
|
||||
draft = setParallelAcknowledgement(draft, "0:1", true);
|
||||
const acknowledged = buildCandidateProfileUpdate(draft, new Date("2026-06-15T00:00:00Z"));
|
||||
expect(acknowledged.data?.confirmed_parallel_periods).toEqual([
|
||||
{
|
||||
first_index: 0,
|
||||
second_index: 1,
|
||||
first_period: { started_on: "2023-01", ended_on: "2024-12" },
|
||||
second_period: { started_on: "2024-01", ended_on: "2025-01" },
|
||||
},
|
||||
]);
|
||||
|
||||
const changed = updateExperienceDraft(draft, "second", { started_on: "2024-02" });
|
||||
expect(changed.parallelAcknowledgements).toEqual({});
|
||||
expect(
|
||||
reviewExperienceOverlaps(changed, new Date("2026-06-15T00:00:00Z"))[0]?.acknowledged,
|
||||
).toBe(false);
|
||||
|
||||
const reordered = moveExperience(draft, 1, -1);
|
||||
expect(reordered.parallelAcknowledgements).toEqual({});
|
||||
expect(
|
||||
reviewExperienceOverlaps(reordered, new Date("2026-06-15T00:00:00Z"))[0]
|
||||
?.requiresAcknowledgement,
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("carries a confirmed overlap only for the original indices and exact date ranges", () => {
|
||||
const profile: CandidateProfile = {
|
||||
...blankProfile(),
|
||||
version: 2,
|
||||
experience: [
|
||||
{
|
||||
employer_name: null,
|
||||
specialization: "backend",
|
||||
started_on: "2023-01",
|
||||
ended_on: "2024-12",
|
||||
summary: null,
|
||||
status: "confirmed",
|
||||
source: {
|
||||
...suggestion,
|
||||
origin: "manual",
|
||||
quote: null,
|
||||
extraction_version: null,
|
||||
confirmed_at: "2026-01-01T00:00:00Z",
|
||||
},
|
||||
},
|
||||
{
|
||||
employer_name: null,
|
||||
specialization: "frontend",
|
||||
started_on: "2024-01",
|
||||
ended_on: "2025-01",
|
||||
summary: null,
|
||||
status: "confirmed",
|
||||
source: {
|
||||
...suggestion,
|
||||
origin: "manual",
|
||||
quote: null,
|
||||
extraction_version: null,
|
||||
confirmed_at: "2026-01-01T00:00:00Z",
|
||||
},
|
||||
},
|
||||
],
|
||||
experience_overlaps: [{ first_index: 0, second_index: 1, status: "confirmed" }],
|
||||
};
|
||||
const draft = toCandidateProfileDraft(profile);
|
||||
expect(
|
||||
reviewExperienceOverlaps(draft, new Date("2026-06-15T00:00:00Z"))[0]?.requiresAcknowledgement,
|
||||
).toBe(false);
|
||||
const changed = updateExperienceDraft(draft, "experience-0", { started_on: "2023-02" });
|
||||
expect(
|
||||
reviewExperienceOverlaps(changed, new Date("2026-06-15T00:00:00Z"))[0]
|
||||
?.requiresAcknowledgement,
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("maps server validation pointers to the corresponding form fields", () => {
|
||||
expect(
|
||||
mapProfileServerErrors([
|
||||
{ pointer: "/contacts/phone/value" },
|
||||
{ pointer: "/experience/2/ended_on" },
|
||||
{ pointer: "/terms/salary_minimum/value/amount" },
|
||||
{ pointer: "/confirmed_parallel_periods/0/first_period/started_on" },
|
||||
]),
|
||||
).toEqual([
|
||||
{ field: "contacts.phone", message: "Проверьте значение и формат этого поля." },
|
||||
{ field: "experience.2.ended_on", message: "Проверьте значение и формат этого поля." },
|
||||
{ field: "terms.salaryMinimum.amount", message: "Проверьте значение и формат этого поля." },
|
||||
{ field: "experience.overlaps", message: "Проверьте значение и формат этого поля." },
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,713 @@
|
||||
import {
|
||||
CandidateProfileUpdate as CandidateProfileUpdateSchema,
|
||||
type CandidateProfile,
|
||||
type CandidateProfileUpdate,
|
||||
} from "../../../shared/api/schemas";
|
||||
|
||||
type ClaimStatus = CandidateProfile["full_name"]["status"];
|
||||
type DecisionStatus = Exclude<ClaimStatus, "unknown">;
|
||||
type ClaimSource = NonNullable<CandidateProfile["full_name"]["source"]>;
|
||||
|
||||
export type FieldDraft<Value> = {
|
||||
value: Value;
|
||||
status: ClaimStatus;
|
||||
originalStatus: ClaimStatus;
|
||||
originalValue: Value | null;
|
||||
source: ClaimSource | null;
|
||||
};
|
||||
|
||||
type ItemMetadata<Value> = {
|
||||
id: string;
|
||||
originalIndex: number | null;
|
||||
status: DecisionStatus;
|
||||
originalStatus: DecisionStatus | null;
|
||||
originalValue: Value | null;
|
||||
source: ClaimSource | null;
|
||||
};
|
||||
|
||||
type StackValue = Pick<CandidateProfile["stack"][number], "tag">;
|
||||
type RoleValue = Omit<
|
||||
Pick<CandidateProfile["roles"][number], "specialization" | "self_assessed_grade">,
|
||||
"specialization"
|
||||
> & { specialization: CandidateProfile["roles"][number]["specialization"] | "" };
|
||||
type ExperienceValue = Omit<
|
||||
Pick<
|
||||
CandidateProfile["experience"][number],
|
||||
"employer_name" | "specialization" | "started_on" | "ended_on" | "summary"
|
||||
>,
|
||||
"specialization"
|
||||
> & { specialization: CandidateProfile["experience"][number]["specialization"] | "" };
|
||||
type SoftSkillValue = Pick<CandidateProfile["soft_skills"][number], "skill">;
|
||||
type SalaryValue = CandidateProfile["terms"]["salary_minimum"]["value"];
|
||||
|
||||
export type StackDraft = StackValue & ItemMetadata<StackValue>;
|
||||
export type RoleDraft = RoleValue & ItemMetadata<RoleValue>;
|
||||
export type ExperienceDraft = ExperienceValue & ItemMetadata<ExperienceValue>;
|
||||
export type SoftSkillDraft = SoftSkillValue & ItemMetadata<SoftSkillValue>;
|
||||
|
||||
export type SalaryDraft = {
|
||||
amount: string;
|
||||
tax_basis: "net" | "gross" | "";
|
||||
status: ClaimStatus;
|
||||
originalStatus: ClaimStatus;
|
||||
originalValue: SalaryValue;
|
||||
source: ClaimSource | null;
|
||||
};
|
||||
|
||||
export type CandidateProfileDraft = {
|
||||
expectedVersion: number;
|
||||
fullName: FieldDraft<string>;
|
||||
contacts: {
|
||||
email: FieldDraft<string>;
|
||||
phone: FieldDraft<string>;
|
||||
telegram: FieldDraft<string>;
|
||||
};
|
||||
stack: StackDraft[];
|
||||
roles: RoleDraft[];
|
||||
experience: ExperienceDraft[];
|
||||
softSkills: SoftSkillDraft[];
|
||||
terms: {
|
||||
location: FieldDraft<string>;
|
||||
relocation: FieldDraft<boolean | null>;
|
||||
salaryMinimum: SalaryDraft;
|
||||
};
|
||||
confirmedCategories: CandidateProfile["confirmed_categories"];
|
||||
originalOverlaps: CandidateProfile["experience_overlaps"];
|
||||
parallelAcknowledgements: Record<string, boolean>;
|
||||
};
|
||||
|
||||
export type ExperienceOverlapReview = {
|
||||
key: string;
|
||||
firstIndex: number;
|
||||
secondIndex: number;
|
||||
firstPeriod: { started_on: string; ended_on: string | null };
|
||||
secondPeriod: { started_on: string; ended_on: string | null };
|
||||
requiresAcknowledgement: boolean;
|
||||
acknowledged: boolean;
|
||||
};
|
||||
|
||||
export type ProfileFormIssue = { field: string; message: string };
|
||||
|
||||
function textFieldDraft(claim: {
|
||||
status: ClaimStatus;
|
||||
value: string | null;
|
||||
source: ClaimSource | null;
|
||||
}): FieldDraft<string> {
|
||||
return {
|
||||
value: claim.value ?? "",
|
||||
status: claim.status,
|
||||
originalStatus: claim.status,
|
||||
originalValue: claim.value,
|
||||
source: claim.source,
|
||||
};
|
||||
}
|
||||
|
||||
function valueFieldDraft<Value>(claim: {
|
||||
status: ClaimStatus;
|
||||
value: Value | null;
|
||||
source: ClaimSource | null;
|
||||
}): FieldDraft<Value | null> {
|
||||
return {
|
||||
value: claim.value,
|
||||
status: claim.status,
|
||||
originalStatus: claim.status,
|
||||
originalValue: claim.value,
|
||||
source: claim.source,
|
||||
};
|
||||
}
|
||||
|
||||
function itemDraft<Value, Item extends { status: DecisionStatus; source: ClaimSource }>(
|
||||
id: string,
|
||||
index: number,
|
||||
item: Item,
|
||||
value: Value,
|
||||
): Value & ItemMetadata<Value> {
|
||||
return {
|
||||
...value,
|
||||
id,
|
||||
originalIndex: index,
|
||||
status: item.status,
|
||||
originalStatus: item.status,
|
||||
originalValue: value,
|
||||
source: item.source,
|
||||
};
|
||||
}
|
||||
|
||||
export function toCandidateProfileDraft(profile: CandidateProfile): CandidateProfileDraft {
|
||||
const salaryValue = profile.terms.salary_minimum.value;
|
||||
return {
|
||||
expectedVersion: profile.version,
|
||||
fullName: textFieldDraft(profile.full_name),
|
||||
contacts: {
|
||||
email: textFieldDraft(profile.contacts.email),
|
||||
phone: textFieldDraft(profile.contacts.phone),
|
||||
telegram: textFieldDraft(profile.contacts.telegram),
|
||||
},
|
||||
stack: profile.stack.map((item, index) =>
|
||||
itemDraft(`stack-${index}`, index, item, { tag: item.tag }),
|
||||
),
|
||||
roles: profile.roles.map((item, index) =>
|
||||
itemDraft(`role-${index}`, index, item, {
|
||||
specialization: item.specialization,
|
||||
self_assessed_grade: item.self_assessed_grade,
|
||||
}),
|
||||
),
|
||||
experience: profile.experience.map((item, index) =>
|
||||
itemDraft(`experience-${index}`, index, item, {
|
||||
employer_name: item.employer_name,
|
||||
specialization: item.specialization,
|
||||
started_on: item.started_on,
|
||||
ended_on: item.ended_on,
|
||||
summary: item.summary,
|
||||
}),
|
||||
),
|
||||
softSkills: profile.soft_skills.map((item, index) =>
|
||||
itemDraft(`soft-skill-${index}`, index, item, { skill: item.skill }),
|
||||
),
|
||||
terms: {
|
||||
location: textFieldDraft(profile.terms.location),
|
||||
relocation: valueFieldDraft(profile.terms.relocation),
|
||||
salaryMinimum: {
|
||||
amount: salaryValue ? String(salaryValue.amount) : "",
|
||||
tax_basis: salaryValue?.tax_basis ?? "",
|
||||
status: profile.terms.salary_minimum.status,
|
||||
originalStatus: profile.terms.salary_minimum.status,
|
||||
originalValue: salaryValue,
|
||||
source: profile.terms.salary_minimum.source,
|
||||
},
|
||||
},
|
||||
confirmedCategories: profile.confirmed_categories,
|
||||
originalOverlaps: profile.experience_overlaps,
|
||||
parallelAcknowledgements: {},
|
||||
};
|
||||
}
|
||||
|
||||
export function updateFieldDraft<Value>(draft: FieldDraft<Value>, value: Value): FieldDraft<Value> {
|
||||
const keepSuggestion =
|
||||
draft.originalStatus === "extracted" && sameValue(value, draft.originalValue);
|
||||
const remainsUnknown = draft.originalStatus === "unknown" && isEmptyValue(value);
|
||||
return {
|
||||
...draft,
|
||||
value,
|
||||
status: keepSuggestion ? "extracted" : remainsUnknown ? "unknown" : "confirmed",
|
||||
};
|
||||
}
|
||||
|
||||
export function updateStackDraft(
|
||||
draft: CandidateProfileDraft,
|
||||
id: string,
|
||||
patch: Partial<StackValue>,
|
||||
): CandidateProfileDraft {
|
||||
return updateItem(draft, "stack", id, patch);
|
||||
}
|
||||
|
||||
export function updateRoleDraft(
|
||||
draft: CandidateProfileDraft,
|
||||
id: string,
|
||||
patch: Partial<RoleValue>,
|
||||
): CandidateProfileDraft {
|
||||
return updateItem(draft, "roles", id, patch);
|
||||
}
|
||||
|
||||
export function updateExperienceDraft(
|
||||
draft: CandidateProfileDraft,
|
||||
id: string,
|
||||
patch: Partial<ExperienceValue>,
|
||||
): CandidateProfileDraft {
|
||||
const dateChanged = "started_on" in patch || "ended_on" in patch;
|
||||
const updated = updateItem(draft, "experience", id, patch);
|
||||
return dateChanged ? { ...updated, parallelAcknowledgements: {} } : updated;
|
||||
}
|
||||
|
||||
export function updateSalaryDraft(
|
||||
draft: CandidateProfileDraft,
|
||||
patch: Partial<Pick<SalaryDraft, "amount" | "tax_basis">>,
|
||||
): CandidateProfileDraft {
|
||||
const next = { ...draft.terms.salaryMinimum, ...patch };
|
||||
const sameOriginal = Boolean(
|
||||
next.amount.trim() !== "" &&
|
||||
next.tax_basis !== "" &&
|
||||
next.originalValue &&
|
||||
Number(next.amount) === next.originalValue.amount &&
|
||||
next.tax_basis === next.originalValue.tax_basis,
|
||||
);
|
||||
const isEmpty = next.amount.trim() === "";
|
||||
return {
|
||||
...draft,
|
||||
terms: {
|
||||
...draft.terms,
|
||||
salaryMinimum: {
|
||||
...next,
|
||||
status:
|
||||
next.originalStatus === "extracted" && sameOriginal
|
||||
? "extracted"
|
||||
: next.originalStatus === "unknown" && isEmpty
|
||||
? "unknown"
|
||||
: "confirmed",
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function updateSoftSkillDraft(
|
||||
draft: CandidateProfileDraft,
|
||||
id: string,
|
||||
patch: Partial<SoftSkillValue>,
|
||||
): CandidateProfileDraft {
|
||||
return updateItem(draft, "softSkills", id, patch);
|
||||
}
|
||||
|
||||
function updateItem<
|
||||
Key extends "stack" | "roles" | "experience" | "softSkills",
|
||||
Item extends CandidateProfileDraft[Key][number],
|
||||
Patch extends Partial<Omit<Item, keyof ItemMetadata<unknown>>>,
|
||||
>(draft: CandidateProfileDraft, key: Key, id: string, patch: Patch): CandidateProfileDraft {
|
||||
const items = draft[key] as Item[];
|
||||
const updatedItems = items.map((item) => {
|
||||
if (item.id !== id) return item;
|
||||
const next = { ...item, ...patch };
|
||||
const unchangedSuggestion =
|
||||
item.originalStatus === "extracted" &&
|
||||
item.originalValue !== null &&
|
||||
sameValue(itemValue(next), item.originalValue);
|
||||
return {
|
||||
...next,
|
||||
status: unchangedSuggestion ? "extracted" : "confirmed",
|
||||
} as Item;
|
||||
});
|
||||
return { ...draft, [key]: updatedItems } as CandidateProfileDraft;
|
||||
}
|
||||
|
||||
function itemValue(item: object): object {
|
||||
const value: Record<string, unknown> = {};
|
||||
for (const [key, itemValue] of Object.entries(item)) {
|
||||
if (
|
||||
key !== "id" &&
|
||||
key !== "originalIndex" &&
|
||||
key !== "status" &&
|
||||
key !== "originalStatus" &&
|
||||
key !== "originalValue" &&
|
||||
key !== "source"
|
||||
) {
|
||||
value[key] = itemValue;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function sameValue(left: unknown, right: unknown): boolean {
|
||||
return JSON.stringify(left) === JSON.stringify(right);
|
||||
}
|
||||
|
||||
function isEmptyValue(value: unknown): boolean {
|
||||
return value === "" || value === null;
|
||||
}
|
||||
|
||||
function monthNumber(value: string): number | null {
|
||||
if (!/^\d{4}-(0[1-9]|1[0-2])$/.test(value)) return null;
|
||||
const year = Number(value.slice(0, 4));
|
||||
const month = Number(value.slice(5, 7));
|
||||
return year * 12 + month - 1;
|
||||
}
|
||||
|
||||
function rangesOverlap(
|
||||
first: ExperienceDraft,
|
||||
second: ExperienceDraft,
|
||||
currentMonth: number,
|
||||
): boolean {
|
||||
const firstStart = monthNumber(first.started_on);
|
||||
const secondStart = monthNumber(second.started_on);
|
||||
const firstEnd = first.ended_on === null ? currentMonth : monthNumber(first.ended_on);
|
||||
const secondEnd = second.ended_on === null ? currentMonth : monthNumber(second.ended_on);
|
||||
if (firstStart === null || secondStart === null || firstEnd === null || secondEnd === null) {
|
||||
return false;
|
||||
}
|
||||
if (firstStart > firstEnd || secondStart > secondEnd) return false;
|
||||
return firstStart <= secondEnd && secondStart <= firstEnd;
|
||||
}
|
||||
|
||||
function samePeriod(current: ExperienceDraft, original: ExperienceValue | null): boolean {
|
||||
return Boolean(
|
||||
original &&
|
||||
current.started_on === original.started_on &&
|
||||
current.ended_on === original.ended_on,
|
||||
);
|
||||
}
|
||||
|
||||
export function reviewExperienceOverlaps(
|
||||
draft: CandidateProfileDraft,
|
||||
now = new Date(),
|
||||
): ExperienceOverlapReview[] {
|
||||
const currentMonth = now.getUTCFullYear() * 12 + now.getUTCMonth();
|
||||
const overlaps: ExperienceOverlapReview[] = [];
|
||||
for (let firstIndex = 0; firstIndex < draft.experience.length; firstIndex += 1) {
|
||||
const first = draft.experience[firstIndex];
|
||||
if (!first) continue;
|
||||
for (
|
||||
let secondIndex = firstIndex + 1;
|
||||
secondIndex < draft.experience.length;
|
||||
secondIndex += 1
|
||||
) {
|
||||
const second = draft.experience[secondIndex];
|
||||
if (!second || !rangesOverlap(first, second, currentMonth)) continue;
|
||||
const key = `${firstIndex}:${secondIndex}`;
|
||||
const prior = draft.originalOverlaps.find(
|
||||
(overlap) => overlap.first_index === firstIndex && overlap.second_index === secondIndex,
|
||||
);
|
||||
const unchangedConfirmed = Boolean(
|
||||
prior?.status === "confirmed" &&
|
||||
first.originalIndex === firstIndex &&
|
||||
second.originalIndex === secondIndex &&
|
||||
samePeriod(first, first.originalValue) &&
|
||||
samePeriod(second, second.originalValue),
|
||||
);
|
||||
overlaps.push({
|
||||
key,
|
||||
firstIndex,
|
||||
secondIndex,
|
||||
firstPeriod: { started_on: first.started_on, ended_on: first.ended_on },
|
||||
secondPeriod: { started_on: second.started_on, ended_on: second.ended_on },
|
||||
requiresAcknowledgement: !unchangedConfirmed,
|
||||
acknowledged: draft.parallelAcknowledgements[key] === true,
|
||||
});
|
||||
}
|
||||
}
|
||||
return overlaps;
|
||||
}
|
||||
|
||||
export function setParallelAcknowledgement(
|
||||
draft: CandidateProfileDraft,
|
||||
key: string,
|
||||
acknowledged: boolean,
|
||||
): CandidateProfileDraft {
|
||||
return {
|
||||
...draft,
|
||||
parallelAcknowledgements: { ...draft.parallelAcknowledgements, [key]: acknowledged },
|
||||
};
|
||||
}
|
||||
|
||||
export function addExperience(draft: CandidateProfileDraft, id: string): CandidateProfileDraft {
|
||||
return {
|
||||
...draft,
|
||||
experience: [
|
||||
...draft.experience,
|
||||
{
|
||||
id,
|
||||
originalIndex: null,
|
||||
employer_name: null,
|
||||
specialization: "",
|
||||
started_on: "",
|
||||
ended_on: null,
|
||||
summary: null,
|
||||
status: "confirmed",
|
||||
originalStatus: null,
|
||||
originalValue: null,
|
||||
source: null,
|
||||
},
|
||||
],
|
||||
parallelAcknowledgements: {},
|
||||
};
|
||||
}
|
||||
|
||||
export function removeExperience(draft: CandidateProfileDraft, id: string): CandidateProfileDraft {
|
||||
return {
|
||||
...draft,
|
||||
experience: draft.experience.filter((item) => item.id !== id),
|
||||
parallelAcknowledgements: {},
|
||||
};
|
||||
}
|
||||
|
||||
export function moveExperience(
|
||||
draft: CandidateProfileDraft,
|
||||
index: number,
|
||||
direction: -1 | 1,
|
||||
): CandidateProfileDraft {
|
||||
const targetIndex = index + direction;
|
||||
if (targetIndex < 0 || targetIndex >= draft.experience.length) return draft;
|
||||
const experience = [...draft.experience];
|
||||
[experience[index], experience[targetIndex]] = [experience[targetIndex]!, experience[index]!];
|
||||
return { ...draft, experience, parallelAcknowledgements: {} };
|
||||
}
|
||||
|
||||
export function addStack(draft: CandidateProfileDraft, id: string): CandidateProfileDraft {
|
||||
return {
|
||||
...draft,
|
||||
stack: [
|
||||
...draft.stack,
|
||||
{
|
||||
id,
|
||||
originalIndex: null,
|
||||
tag: "",
|
||||
status: "confirmed",
|
||||
originalStatus: null,
|
||||
originalValue: null,
|
||||
source: null,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
export function addRole(draft: CandidateProfileDraft, id: string): CandidateProfileDraft {
|
||||
return {
|
||||
...draft,
|
||||
roles: [
|
||||
...draft.roles,
|
||||
{
|
||||
id,
|
||||
originalIndex: null,
|
||||
specialization: "",
|
||||
self_assessed_grade: null,
|
||||
status: "confirmed",
|
||||
originalStatus: null,
|
||||
originalValue: null,
|
||||
source: null,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
export function addSoftSkill(draft: CandidateProfileDraft, id: string): CandidateProfileDraft {
|
||||
return {
|
||||
...draft,
|
||||
softSkills: [
|
||||
...draft.softSkills,
|
||||
{
|
||||
id,
|
||||
originalIndex: null,
|
||||
skill: "",
|
||||
status: "confirmed",
|
||||
originalStatus: null,
|
||||
originalValue: null,
|
||||
source: null,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
export function removeItem<Key extends "stack" | "roles" | "softSkills">(
|
||||
draft: CandidateProfileDraft,
|
||||
key: Key,
|
||||
id: string,
|
||||
): CandidateProfileDraft {
|
||||
return { ...draft, [key]: draft[key].filter((item) => item.id !== id) } as CandidateProfileDraft;
|
||||
}
|
||||
|
||||
function fieldDecision<Value>(
|
||||
draft: FieldDraft<Value>,
|
||||
value = draft.value,
|
||||
): { value: Exclude<Value, null | "">; status: DecisionStatus } | null {
|
||||
if (isEmptyValue(value)) return null;
|
||||
const extracted = draft.status === "extracted" && sameValue(value, draft.originalValue);
|
||||
return {
|
||||
value: value as Exclude<Value, null | "">,
|
||||
status: extracted ? "extracted" : "confirmed",
|
||||
};
|
||||
}
|
||||
|
||||
function itemDecision<Value>(
|
||||
item: Value & ItemMetadata<Value>,
|
||||
): Value & { status: DecisionStatus } {
|
||||
const extracted =
|
||||
item.status === "extracted" &&
|
||||
item.originalValue !== null &&
|
||||
sameValue(itemValue(item), item.originalValue);
|
||||
return { ...itemValue(item), status: extracted ? "extracted" : "confirmed" } as Value & {
|
||||
status: DecisionStatus;
|
||||
};
|
||||
}
|
||||
|
||||
function escapePointerSegment(value: string | number): string {
|
||||
return String(value).replaceAll("~", "~0").replaceAll("/", "~1");
|
||||
}
|
||||
|
||||
function fieldForPointer(pointer: string): string {
|
||||
const parts = pointer
|
||||
.split("/")
|
||||
.slice(1)
|
||||
.map((part) => part.replaceAll("~1", "/").replaceAll("~0", "~"));
|
||||
const [root, index, property, detail] = parts;
|
||||
if (root === "full_name") return "fullName";
|
||||
if (root === "contacts" && index) return `contacts.${index}`;
|
||||
if (root === "stack" && index !== undefined) return `stack.${index}.${property ?? "tag"}`;
|
||||
if (root === "roles" && index !== undefined)
|
||||
return `roles.${index}.${property ?? "specialization"}`;
|
||||
if (root === "experience" && index !== undefined)
|
||||
return `experience.${index}.${property ?? "started_on"}`;
|
||||
if (root === "soft_skills" && index !== undefined) return `softSkills.${index}.skill`;
|
||||
if (root === "terms" && index) {
|
||||
if (index === "salary_minimum") {
|
||||
return property === "value"
|
||||
? `terms.salaryMinimum.${detail ?? "amount"}`
|
||||
: "terms.salaryMinimum";
|
||||
}
|
||||
return `terms.${index}`;
|
||||
}
|
||||
if (root === "confirmed_parallel_periods") return "experience.overlaps";
|
||||
if (root === "expected_version" || !root) return "form";
|
||||
return "form";
|
||||
}
|
||||
|
||||
function zodPointer(path: readonly PropertyKey[]): string {
|
||||
return `/${path.map((part) => escapePointerSegment(String(part))).join("/")}`;
|
||||
}
|
||||
|
||||
function monthIsFuture(value: string, now: Date): boolean {
|
||||
const month = monthNumber(value);
|
||||
if (month === null) return false;
|
||||
const current = now.getUTCFullYear() * 12 + now.getUTCMonth();
|
||||
return month > current;
|
||||
}
|
||||
|
||||
function customValidationIssues(draft: CandidateProfileDraft, now: Date): ProfileFormIssue[] {
|
||||
const issues: ProfileFormIssue[] = [];
|
||||
const duplicates = <Value>(
|
||||
items: Value[],
|
||||
valueOf: (value: Value) => string,
|
||||
fieldOfIndex: (index: number) => string,
|
||||
) => {
|
||||
const seen = new Set<string>();
|
||||
items.forEach((item, index) => {
|
||||
const value = valueOf(item).trim().toLocaleLowerCase("ru");
|
||||
if (!value) return;
|
||||
if (seen.has(value)) {
|
||||
issues.push({ field: fieldOfIndex(index), message: "Повторяющееся значение." });
|
||||
}
|
||||
seen.add(value);
|
||||
});
|
||||
};
|
||||
duplicates(
|
||||
draft.stack,
|
||||
(item) => item.tag,
|
||||
(index) => `stack.${index}.tag`,
|
||||
);
|
||||
duplicates(
|
||||
draft.roles,
|
||||
(item) => item.specialization,
|
||||
(index) => `roles.${index}.specialization`,
|
||||
);
|
||||
duplicates(
|
||||
draft.softSkills,
|
||||
(item) => item.skill,
|
||||
(index) => `softSkills.${index}.skill`,
|
||||
);
|
||||
draft.experience.forEach((item, index) => {
|
||||
const start = monthNumber(item.started_on);
|
||||
const end = item.ended_on === null ? null : monthNumber(item.ended_on);
|
||||
if (start !== null && monthIsFuture(item.started_on, now)) {
|
||||
issues.push({
|
||||
field: `experience.${index}.started_on`,
|
||||
message: "Месяц не может быть в будущем.",
|
||||
});
|
||||
}
|
||||
if (item.ended_on !== null && end !== null && monthIsFuture(item.ended_on, now)) {
|
||||
issues.push({
|
||||
field: `experience.${index}.ended_on`,
|
||||
message: "Месяц не может быть в будущем.",
|
||||
});
|
||||
}
|
||||
if (start !== null && end !== null && end < start) {
|
||||
issues.push({
|
||||
field: `experience.${index}.ended_on`,
|
||||
message: "Месяц окончания должен быть не раньше начала.",
|
||||
});
|
||||
}
|
||||
});
|
||||
if (draft.terms.salaryMinimum.amount.trim() && !draft.terms.salaryMinimum.tax_basis) {
|
||||
issues.push({
|
||||
field: "terms.salaryMinimum.tax_basis",
|
||||
message: "Выберите, указана сумма до или после налога.",
|
||||
});
|
||||
}
|
||||
for (const overlap of reviewExperienceOverlaps(draft, now)) {
|
||||
if (overlap.requiresAcknowledgement && !overlap.acknowledged) {
|
||||
issues.push({
|
||||
field: "experience.overlaps",
|
||||
message: `Подтвердите отдельно, что периоды ${overlap.firstIndex + 1} и ${overlap.secondIndex + 1} действительно шли параллельно.`,
|
||||
});
|
||||
}
|
||||
}
|
||||
return issues;
|
||||
}
|
||||
|
||||
export function profilePointerField(pointer: string): string {
|
||||
return fieldForPointer(pointer);
|
||||
}
|
||||
|
||||
export function buildCandidateProfileUpdate(
|
||||
draft: CandidateProfileDraft,
|
||||
now = new Date(),
|
||||
): { data: CandidateProfileUpdate | null; issues: ProfileFormIssue[] } {
|
||||
const salaryAmount = draft.terms.salaryMinimum.amount.trim();
|
||||
const salaryValue: SalaryValue =
|
||||
salaryAmount && draft.terms.salaryMinimum.tax_basis
|
||||
? {
|
||||
amount: Number(salaryAmount),
|
||||
currency: "RUB",
|
||||
period: "month",
|
||||
tax_basis: draft.terms.salaryMinimum.tax_basis,
|
||||
}
|
||||
: null;
|
||||
const data: unknown = {
|
||||
expected_version: draft.expectedVersion,
|
||||
full_name: fieldDecision(draft.fullName, draft.fullName.value.trim()),
|
||||
contacts: {
|
||||
email: fieldDecision(draft.contacts.email, draft.contacts.email.value.trim()),
|
||||
phone: fieldDecision(draft.contacts.phone, draft.contacts.phone.value.trim()),
|
||||
telegram: fieldDecision(draft.contacts.telegram, draft.contacts.telegram.value.trim()),
|
||||
},
|
||||
stack: draft.stack.filter((item) => item.tag.trim()).map(itemDecision),
|
||||
roles: draft.roles.map(itemDecision),
|
||||
experience: draft.experience.map((item) =>
|
||||
itemDecision({
|
||||
...item,
|
||||
employer_name: item.employer_name?.trim() || null,
|
||||
summary: item.summary?.trim() || null,
|
||||
}),
|
||||
),
|
||||
confirmed_parallel_periods: reviewExperienceOverlaps(draft, now)
|
||||
.filter((overlap) => overlap.requiresAcknowledgement && overlap.acknowledged)
|
||||
.map((overlap) => ({
|
||||
first_index: overlap.firstIndex,
|
||||
second_index: overlap.secondIndex,
|
||||
first_period: overlap.firstPeriod,
|
||||
second_period: overlap.secondPeriod,
|
||||
})),
|
||||
soft_skills: draft.softSkills.filter((item) => item.skill.trim()).map(itemDecision),
|
||||
terms: {
|
||||
location: fieldDecision(draft.terms.location, draft.terms.location.value.trim()),
|
||||
relocation: fieldDecision(draft.terms.relocation),
|
||||
salary_minimum: salaryValue
|
||||
? {
|
||||
value: salaryValue,
|
||||
status:
|
||||
draft.terms.salaryMinimum.status === "extracted" &&
|
||||
sameValue(salaryValue, draft.terms.salaryMinimum.originalValue)
|
||||
? "extracted"
|
||||
: "confirmed",
|
||||
}
|
||||
: null,
|
||||
},
|
||||
};
|
||||
|
||||
const issues = customValidationIssues(draft, now);
|
||||
const parsed = CandidateProfileUpdateSchema.safeParse(data);
|
||||
if (!parsed.success) {
|
||||
issues.push(
|
||||
...parsed.error.issues.map((issue) => ({
|
||||
field: fieldForPointer(zodPointer(issue.path)),
|
||||
message: "Проверьте значение и формат этого поля.",
|
||||
})),
|
||||
);
|
||||
}
|
||||
return {
|
||||
data: issues.length === 0 && parsed.success ? (parsed.data as CandidateProfileUpdate) : null,
|
||||
issues,
|
||||
};
|
||||
}
|
||||
|
||||
export function mapProfileServerErrors(errors: readonly { pointer: string }[]): ProfileFormIssue[] {
|
||||
return errors.map((error) => ({
|
||||
field: fieldForPointer(error.pointer),
|
||||
message: "Проверьте значение и формат этого поля.",
|
||||
}));
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
export {
|
||||
buildCompanyCreateBody,
|
||||
buildCompanyUpdateBody,
|
||||
draftFromOrganization,
|
||||
emptyCompanyDraft,
|
||||
rebaseCompanyDraft,
|
||||
type CompanyDraft,
|
||||
type CompanyRepresentativeDraft,
|
||||
} from "./model/company-form";
|
||||
export {
|
||||
organizationBasisLabels,
|
||||
organizationLevelLabels,
|
||||
organizationTrustLevel,
|
||||
candidateCardLevelLabels,
|
||||
} from "./model/verification-labels";
|
||||
export { CandidateCardPreview } from "./ui/candidate-card-preview";
|
||||
@@ -0,0 +1,103 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
buildCompanyCreateBody,
|
||||
buildCompanyUpdateBody,
|
||||
draftFromOrganization,
|
||||
emptyCompanyDraft,
|
||||
rebaseCompanyDraft,
|
||||
} from "./company-form";
|
||||
import type { Organization } from "../../../shared/api/schemas";
|
||||
|
||||
const organization: Organization = {
|
||||
id: "9869e1e3-02b2-460e-9b36-ef82e970bb77",
|
||||
version: 4,
|
||||
name: "North Star",
|
||||
description: "Hiring tools",
|
||||
sphere: "Software",
|
||||
contacts: {
|
||||
website: "https://north.example",
|
||||
email: "jobs@north.example",
|
||||
phone: null,
|
||||
telegram: null,
|
||||
},
|
||||
representatives: [{ name: "Ada Lovelace", job_title: "Founder" }],
|
||||
verification: {
|
||||
level: "e0",
|
||||
basis: "confirmed_email",
|
||||
changed_at: "2026-10-01T10:00:00Z",
|
||||
},
|
||||
candidate_card: {
|
||||
id: "9869e1e3-02b2-460e-9b36-ef82e970bb77",
|
||||
name: "North Star",
|
||||
description: "Hiring tools",
|
||||
sphere: "Software",
|
||||
contacts: {
|
||||
website: "https://north.example",
|
||||
email: "jobs@north.example",
|
||||
phone: null,
|
||||
telegram: null,
|
||||
},
|
||||
representatives: [{ name: "Ada Lovelace", job_title: "Founder" }],
|
||||
verification_level: "e0",
|
||||
},
|
||||
created_at: "2026-10-01T10:00:00Z",
|
||||
updated_at: "2026-10-01T10:00:00Z",
|
||||
};
|
||||
|
||||
describe("company form mapping", () => {
|
||||
it("keeps an empty create body limited to the required name", () => {
|
||||
expect(buildCompanyCreateBody({ ...emptyCompanyDraft(), name: "North Star" })).toEqual({
|
||||
name: "North Star",
|
||||
});
|
||||
});
|
||||
|
||||
it("sends contacts as a complete replacement when any contact changes", () => {
|
||||
const draft = draftFromOrganization(organization);
|
||||
draft.email = "people@north.example";
|
||||
draft.website = "";
|
||||
|
||||
expect(buildCompanyUpdateBody(draft, organization)).toEqual({
|
||||
expected_version: 4,
|
||||
contacts: {
|
||||
website: null,
|
||||
email: "people@north.example",
|
||||
phone: null,
|
||||
telegram: null,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("uses null to clear optional text and replaces representatives as a whole", () => {
|
||||
const draft = draftFromOrganization(organization);
|
||||
draft.description = "";
|
||||
draft.representatives = [];
|
||||
|
||||
expect(buildCompanyUpdateBody(draft, organization)).toEqual({
|
||||
expected_version: 4,
|
||||
description: null,
|
||||
representatives: [],
|
||||
});
|
||||
});
|
||||
|
||||
it("rebases untouched fields while preserving the user draft after a version conflict", () => {
|
||||
const draft = draftFromOrganization(organization);
|
||||
draft.name = "North Star Labs";
|
||||
const latest: Organization = {
|
||||
...organization,
|
||||
version: 5,
|
||||
sphere: "Financial software",
|
||||
candidate_card: { ...organization.candidate_card, sphere: "Financial software" },
|
||||
};
|
||||
|
||||
expect(rebaseCompanyDraft(draft, organization, latest)).toEqual({
|
||||
...draft,
|
||||
sphere: "Financial software",
|
||||
});
|
||||
expect(buildCompanyUpdateBody(rebaseCompanyDraft(draft, organization, latest), latest)).toEqual(
|
||||
{
|
||||
expected_version: 5,
|
||||
name: "North Star Labs",
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,157 @@
|
||||
import type {
|
||||
Organization,
|
||||
OrganizationCreate,
|
||||
OrganizationUpdate,
|
||||
} from "../../../shared/api/schemas";
|
||||
|
||||
export type CompanyRepresentativeDraft = {
|
||||
name: string;
|
||||
job_title: string;
|
||||
};
|
||||
|
||||
export type CompanyDraft = {
|
||||
name: string;
|
||||
description: string;
|
||||
sphere: string;
|
||||
website: string;
|
||||
email: string;
|
||||
phone: string;
|
||||
telegram: string;
|
||||
representatives: CompanyRepresentativeDraft[];
|
||||
};
|
||||
|
||||
const emptyDraft: CompanyDraft = {
|
||||
name: "",
|
||||
description: "",
|
||||
sphere: "",
|
||||
website: "",
|
||||
email: "",
|
||||
phone: "",
|
||||
telegram: "",
|
||||
representatives: [],
|
||||
};
|
||||
|
||||
export function draftFromOrganization(organization: Organization): CompanyDraft {
|
||||
return {
|
||||
name: organization.name,
|
||||
description: organization.description ?? "",
|
||||
sphere: organization.sphere ?? "",
|
||||
website: organization.contacts.website ?? "",
|
||||
email: organization.contacts.email ?? "",
|
||||
phone: organization.contacts.phone ?? "",
|
||||
telegram: organization.contacts.telegram ?? "",
|
||||
representatives: organization.representatives.map((representative) => ({ ...representative })),
|
||||
};
|
||||
}
|
||||
|
||||
function contactValues(draft: CompanyDraft) {
|
||||
return {
|
||||
website: draft.website === "" ? null : draft.website,
|
||||
email: draft.email === "" ? null : draft.email,
|
||||
phone: draft.phone === "" ? null : draft.phone,
|
||||
telegram: draft.telegram === "" ? null : draft.telegram,
|
||||
};
|
||||
}
|
||||
|
||||
function hasPublicContacts(draft: CompanyDraft): boolean {
|
||||
return [draft.website, draft.email, draft.phone, draft.telegram].some((value) => value !== "");
|
||||
}
|
||||
|
||||
function sameRepresentatives(
|
||||
left: readonly CompanyRepresentativeDraft[],
|
||||
right: readonly CompanyRepresentativeDraft[],
|
||||
): boolean {
|
||||
return (
|
||||
left.length === right.length &&
|
||||
left.every(
|
||||
(representative, index) =>
|
||||
representative.name === right[index]?.name &&
|
||||
representative.job_title === right[index]?.job_title,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function contactsChanged(draft: CompanyDraft, organization: Organization): boolean {
|
||||
const values = contactValues(draft);
|
||||
return (
|
||||
values.website !== organization.contacts.website ||
|
||||
values.email !== organization.contacts.email ||
|
||||
values.phone !== organization.contacts.phone ||
|
||||
values.telegram !== organization.contacts.telegram
|
||||
);
|
||||
}
|
||||
|
||||
export function buildCompanyCreateBody(draft: CompanyDraft): OrganizationCreate {
|
||||
const body: OrganizationCreate = { name: draft.name };
|
||||
|
||||
if (draft.description !== "") body.description = draft.description;
|
||||
if (draft.sphere !== "") body.sphere = draft.sphere;
|
||||
if (hasPublicContacts(draft)) body.contacts = contactValues(draft);
|
||||
if (draft.representatives.length > 0) {
|
||||
body.representatives = draft.representatives.map((representative) => ({ ...representative }));
|
||||
}
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
export function buildCompanyUpdateBody(
|
||||
draft: CompanyDraft,
|
||||
organization: Organization,
|
||||
): OrganizationUpdate {
|
||||
const body: OrganizationUpdate = { expected_version: organization.version };
|
||||
|
||||
if (draft.name !== organization.name) body.name = draft.name;
|
||||
if ((draft.description || null) !== organization.description) {
|
||||
body.description = draft.description === "" ? null : draft.description;
|
||||
}
|
||||
if ((draft.sphere || null) !== organization.sphere) {
|
||||
body.sphere = draft.sphere === "" ? null : draft.sphere;
|
||||
}
|
||||
if (contactsChanged(draft, organization)) body.contacts = contactValues(draft);
|
||||
if (!sameRepresentatives(draft.representatives, organization.representatives)) {
|
||||
body.representatives = draft.representatives.map((representative) => ({ ...representative }));
|
||||
}
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
export function rebaseCompanyDraft(
|
||||
previousDraft: CompanyDraft,
|
||||
previousOrganization: Organization,
|
||||
latestOrganization: Organization,
|
||||
): CompanyDraft {
|
||||
const latestDraft = draftFromOrganization(latestOrganization);
|
||||
const previousBaseline = draftFromOrganization(previousOrganization);
|
||||
|
||||
return {
|
||||
...latestDraft,
|
||||
name: previousDraft.name !== previousBaseline.name ? previousDraft.name : latestDraft.name,
|
||||
description:
|
||||
previousDraft.description !== previousBaseline.description
|
||||
? previousDraft.description
|
||||
: latestDraft.description,
|
||||
sphere:
|
||||
previousDraft.sphere !== previousBaseline.sphere ? previousDraft.sphere : latestDraft.sphere,
|
||||
...(contactsChanged(previousDraft, previousOrganization)
|
||||
? {
|
||||
website: previousDraft.website,
|
||||
email: previousDraft.email,
|
||||
phone: previousDraft.phone,
|
||||
telegram: previousDraft.telegram,
|
||||
}
|
||||
: {}),
|
||||
representatives: sameRepresentatives(
|
||||
previousDraft.representatives,
|
||||
previousBaseline.representatives,
|
||||
)
|
||||
? latestDraft.representatives
|
||||
: previousDraft.representatives.map((representative) => ({ ...representative })),
|
||||
};
|
||||
}
|
||||
|
||||
export function emptyCompanyDraft(): CompanyDraft {
|
||||
return {
|
||||
...emptyDraft,
|
||||
representatives: [],
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import type { Organization } from "../../../shared/api/schemas";
|
||||
import type { TrustLevelValue } from "../../../shared/ui";
|
||||
|
||||
export const organizationLevelLabels: Readonly<
|
||||
Record<Organization["verification"]["level"], string>
|
||||
> = {
|
||||
e0: "E0 - подтверждена почта владельца",
|
||||
e1: "E1 - подтверждены домен и связь с компанией",
|
||||
e2: "E2 - проверены реквизиты и полномочия",
|
||||
e3: "E3 - дополнительная проверка платформы",
|
||||
};
|
||||
|
||||
export const candidateCardLevelLabels: Readonly<
|
||||
Record<Organization["candidate_card"]["verification_level"], string>
|
||||
> = {
|
||||
e0: "Уровень E0",
|
||||
e1: "Уровень E1",
|
||||
e2: "Уровень E2",
|
||||
e3: "Уровень E3",
|
||||
};
|
||||
|
||||
export const organizationBasisLabels: Readonly<
|
||||
Record<Organization["verification"]["basis"], string>
|
||||
> = {
|
||||
confirmed_email: "Подтвержденная почта владельца",
|
||||
corporate_domain: "Корпоративный домен и связь с компанией",
|
||||
requisites_and_authority: "Проверка реквизитов и полномочий",
|
||||
manual_review: "Ручная проверка платформы",
|
||||
partner_status: "Статус партнера",
|
||||
};
|
||||
|
||||
export const organizationTrustLevel: Readonly<
|
||||
Record<Organization["verification"]["level"], TrustLevelValue>
|
||||
> = {
|
||||
e0: "claimed",
|
||||
e1: "partial",
|
||||
e2: "confirmed",
|
||||
e3: "confirmed",
|
||||
};
|
||||
@@ -0,0 +1,95 @@
|
||||
.card {
|
||||
display: grid;
|
||||
gap: var(--space-4);
|
||||
min-width: 0;
|
||||
padding: var(--space-4);
|
||||
border: var(--line-thin) solid var(--color-divider);
|
||||
border-radius: var(--radius-m);
|
||||
background: var(--color-surface);
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-3) var(--space-5);
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.name {
|
||||
overflow-wrap: anywhere;
|
||||
font-size: var(--font-size-l);
|
||||
font-weight: var(--font-weight-bold);
|
||||
}
|
||||
|
||||
.level,
|
||||
.sphere,
|
||||
.description {
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.sphere {
|
||||
max-width: 24rem;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.description {
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.contacts {
|
||||
display: grid;
|
||||
gap: var(--space-2);
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.contact {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(8rem, max-content) minmax(0, 1fr);
|
||||
gap: var(--space-2) var(--space-4);
|
||||
}
|
||||
|
||||
.contact dt {
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.contact dd {
|
||||
min-width: 0;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.representatives {
|
||||
display: grid;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
.representatives h4 {
|
||||
font-weight: var(--font-weight-bold);
|
||||
}
|
||||
|
||||
.representatives ul {
|
||||
display: grid;
|
||||
gap: var(--space-2);
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.representatives li {
|
||||
display: grid;
|
||||
gap: var(--space-1);
|
||||
}
|
||||
|
||||
.representatives li span + span {
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
@media (width < 30rem) {
|
||||
.card {
|
||||
padding: var(--space-3);
|
||||
}
|
||||
|
||||
.contact {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
gap: var(--space-1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { CandidateCardPreview } from "./candidate-card-preview";
|
||||
import type { Organization } from "../../../shared/api/schemas";
|
||||
|
||||
const card: Organization["candidate_card"] = {
|
||||
id: "9869e1e3-02b2-460e-9b36-ef82e970bb77",
|
||||
name: "North Star",
|
||||
description: "Candidate-facing profile",
|
||||
sphere: "Software",
|
||||
contacts: {
|
||||
website: "https://north.example",
|
||||
email: "careers@north.example",
|
||||
phone: null,
|
||||
telegram: null,
|
||||
},
|
||||
representatives: [{ name: "Ada Lovelace", job_title: "Founder" }],
|
||||
verification_level: "e0",
|
||||
};
|
||||
|
||||
describe("candidate card preview", () => {
|
||||
it("renders the card fields and omits membership, account, and verification basis", () => {
|
||||
const markup = renderToStaticMarkup(<CandidateCardPreview card={card} />);
|
||||
const preview = /<article[^>]*>(.*?)<\/article>/.exec(markup)?.[1];
|
||||
|
||||
expect(preview).toContain("North Star");
|
||||
expect(preview).toContain("Candidate-facing profile");
|
||||
expect(preview).toContain("Software");
|
||||
expect(preview).toContain("careers@north.example");
|
||||
expect(preview).toContain("Ada Lovelace");
|
||||
expect(preview).toContain("Уровень E0");
|
||||
expect(preview).not.toMatch(/membership|role|account|version|basis|владелец/i);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,70 @@
|
||||
import type { Organization } from "../../../shared/api/schemas";
|
||||
import { Section, TrustLevel } from "../../../shared/ui";
|
||||
import { candidateCardLevelLabels, organizationTrustLevel } from "../model/verification-labels";
|
||||
import styles from "./candidate-card-preview.module.css";
|
||||
|
||||
type CandidateCard = Organization["candidate_card"];
|
||||
|
||||
type CandidateCardPreviewProps = {
|
||||
card: CandidateCard;
|
||||
};
|
||||
|
||||
const contactLabels = {
|
||||
website: "Сайт",
|
||||
email: "Почта для связи",
|
||||
phone: "Телефон компании",
|
||||
telegram: "Telegram компании",
|
||||
} as const;
|
||||
|
||||
export function CandidateCardPreview({ card }: CandidateCardPreviewProps) {
|
||||
const contacts = (Object.keys(contactLabels) as (keyof typeof contactLabels)[]).flatMap((key) => {
|
||||
const value = card.contacts[key];
|
||||
return value ? [{ label: contactLabels[key], value }] : [];
|
||||
});
|
||||
|
||||
return (
|
||||
<Section
|
||||
title="Так карточку увидит кандидат"
|
||||
description="Проверьте описание и контакты, которые увидит кандидат."
|
||||
>
|
||||
<article className={styles.card} aria-label="Предпросмотр карточки компании">
|
||||
<header className={styles.header}>
|
||||
<div>
|
||||
<h3 className={styles.name}>{card.name}</h3>
|
||||
<p className={styles.level}>
|
||||
<TrustLevel
|
||||
level={organizationTrustLevel[card.verification_level]}
|
||||
label={candidateCardLevelLabels[card.verification_level]}
|
||||
/>
|
||||
</p>
|
||||
</div>
|
||||
{card.sphere ? <p className={styles.sphere}>{card.sphere}</p> : null}
|
||||
</header>
|
||||
{card.description ? <p className={styles.description}>{card.description}</p> : null}
|
||||
{contacts.length > 0 ? (
|
||||
<dl className={styles.contacts}>
|
||||
{contacts.map(({ label, value }) => (
|
||||
<div className={styles.contact} key={label}>
|
||||
<dt>{label}</dt>
|
||||
<dd>{value}</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
) : null}
|
||||
{card.representatives && card.representatives.length > 0 ? (
|
||||
<div className={styles.representatives}>
|
||||
<h4>Представители компании</h4>
|
||||
<ul>
|
||||
{card.representatives.map((representative, index) => (
|
||||
<li key={`${representative.name}-${index}`}>
|
||||
<span>{representative.name}</span>
|
||||
<span>{representative.job_title}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
) : null}
|
||||
</article>
|
||||
</Section>
|
||||
);
|
||||
}
|
||||
@@ -14,7 +14,7 @@ describe("getOnboardingDestination", () => {
|
||||
it.each([
|
||||
["candidate", "candidate_consents", paths.candidate.onboarding],
|
||||
["candidate", "candidate_profile", paths.candidate.profile],
|
||||
["candidate", "candidate_questionnaire", paths.candidate.onboarding],
|
||||
["candidate", "candidate_questionnaire", paths.candidate.questionnaire],
|
||||
["candidate", "candidate_assessment", paths.candidate.assessment],
|
||||
["candidate", "completed", paths.candidate.root],
|
||||
["employer", "employer_company", paths.employer.company],
|
||||
|
||||
@@ -11,8 +11,9 @@ export function getOnboardingDestination(
|
||||
|
||||
switch (account.onboarding_step) {
|
||||
case "candidate_consents":
|
||||
case "candidate_questionnaire":
|
||||
return paths.candidate.onboarding;
|
||||
case "candidate_questionnaire":
|
||||
return paths.candidate.questionnaire;
|
||||
case "candidate_profile":
|
||||
return paths.candidate.profile;
|
||||
case "candidate_assessment":
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
export {
|
||||
findGradeTitle,
|
||||
findSpecializationOption,
|
||||
listSpecializationOptions,
|
||||
type CatalogSpecializationOption,
|
||||
} from "./model/catalog";
|
||||
@@ -0,0 +1,71 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { SpecializationCatalog } from "../../../shared/api/schemas";
|
||||
import { findGradeTitle, findSpecializationOption, listSpecializationOptions } from "./catalog";
|
||||
|
||||
const catalog: SpecializationCatalog = {
|
||||
directions: [
|
||||
{
|
||||
code: "development",
|
||||
title: "Разработка",
|
||||
specializations: [
|
||||
{
|
||||
code: "backend",
|
||||
title: "Backend",
|
||||
test_availability: {
|
||||
status: "available",
|
||||
grades: ["junior"],
|
||||
task_languages: ["go"],
|
||||
note: null,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
code: "data",
|
||||
title: "Данные",
|
||||
specializations: [
|
||||
{
|
||||
code: "ds_ml",
|
||||
title: "DS/ML",
|
||||
test_availability: {
|
||||
status: "in_development",
|
||||
grades: [],
|
||||
task_languages: [],
|
||||
note: "Банк заданий готовится.",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
grades: [
|
||||
{ code: "intern", title: "Стажер" },
|
||||
{ code: "junior", title: "Junior" },
|
||||
{ code: "middle", title: "Middle" },
|
||||
{ code: "senior", title: "Senior" },
|
||||
],
|
||||
};
|
||||
|
||||
describe("specialization catalog helpers", () => {
|
||||
it("keeps the server's direction and specialization order", () => {
|
||||
expect(
|
||||
listSpecializationOptions(catalog).map((option) => [option.directionTitle, option.code]),
|
||||
).toEqual([
|
||||
["Разработка", "backend"],
|
||||
["Данные", "ds_ml"],
|
||||
]);
|
||||
});
|
||||
|
||||
it("returns current availability without inferring it from a code", () => {
|
||||
expect(findSpecializationOption(catalog, "ds_ml")?.test_availability).toEqual({
|
||||
status: "in_development",
|
||||
grades: [],
|
||||
task_languages: [],
|
||||
note: "Банк заданий готовится.",
|
||||
});
|
||||
expect(findSpecializationOption(catalog, "")).toBeNull();
|
||||
});
|
||||
|
||||
it("uses grade titles from the public catalog", () => {
|
||||
expect(findGradeTitle(catalog, "junior")).toBe("Junior");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
import type {
|
||||
CatalogGrade,
|
||||
CatalogSpecialization,
|
||||
SpecializationCatalog,
|
||||
SpecializationCode,
|
||||
} from "../../../shared/api/schemas";
|
||||
|
||||
export type CatalogSpecializationOption = CatalogSpecialization & {
|
||||
directionCode: SpecializationCatalog["directions"][number]["code"];
|
||||
directionTitle: string;
|
||||
};
|
||||
|
||||
export function listSpecializationOptions(
|
||||
catalog: SpecializationCatalog,
|
||||
): CatalogSpecializationOption[] {
|
||||
return catalog.directions.flatMap((direction) =>
|
||||
direction.specializations.map((specialization) => ({
|
||||
...specialization,
|
||||
directionCode: direction.code,
|
||||
directionTitle: direction.title,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
export function findSpecializationOption(
|
||||
catalog: SpecializationCatalog,
|
||||
code: SpecializationCode | "",
|
||||
): CatalogSpecializationOption | null {
|
||||
if (!code) return null;
|
||||
return listSpecializationOptions(catalog).find((option) => option.code === code) ?? null;
|
||||
}
|
||||
|
||||
export function findGradeTitle(catalog: SpecializationCatalog, code: CatalogGrade["code"]): string {
|
||||
return catalog.grades.find((grade) => grade.code === code)?.title ?? code;
|
||||
}
|
||||
Reference in new issue
Block a user