feat(invitations): add the candidate invitation inbox with C4 acceptance and decline

This commit is contained in:
shira committed 2026-10-09 20:30:35 +03:00
1 parent 12a7213d4a
commit a856066316
54 files changed
+3897 -136

No files matched your search

@@ -1,4 +1,6 @@
// Public API of the invitation-preview widget: the company card and the
// terms of an invitation as the candidate sees them.
// terms of an invitation as the candidate sees them, and the terms alone for
// a candidate reading an invitation addressed to them.
export { InvitationPreview } from "./ui/invitation-preview";
export { InvitationTermsArticle } from "./ui/invitation-terms";
@@ -1,17 +1,7 @@
import type { ReactNode } from "react";
import type { CandidateOrganizationCard, InvitationTerms } from "../../../shared/api/schemas";
import { CompanyCardView } from "../../../entities/company";
import {
communicationChannelLabels,
formatSalaryRange,
formatServerMoment,
notProvidedLabel,
offerTypeLabels,
packageItemKeys,
packageItemLabels,
responsePeriodLabel,
} from "../../../entities/invitation";
import { gradeLabels, specializationLabels, workFormatLabels } from "../../../entities/match";
import { InvitationTermsArticle } from "./invitation-terms";
import styles from "./invitation-preview.module.css";
type InvitationPreviewProps = {
@@ -40,12 +30,6 @@ export function InvitationPreview({
responseDeadlineAt,
title = "Так приглашение увидит кандидат",
}: InvitationPreviewProps) {
const location =
terms.location ??
(terms.work_formats.every((format) => format === "remote")
? "Не требуется: только удаленная работа"
: "Не указано");
return (
<div className={styles.root}>
<div className={styles.heading}>
@@ -58,89 +42,11 @@ export function InvitationPreview({
<section className={styles.company} aria-label="Компания">
{card ? <CompanyCardView card={card} headingLevel={4} /> : cardFallback}
</section>
<article className={styles.terms} aria-label="Условия приглашения">
<h4 className={styles.role}>{terms.role_title}</h4>
<dl className={styles.facts}>
<div className={styles.fact}>
<dt>Специализация и грейд</dt>
<dd>{`${specializationLabels[terms.specialization]}, ${gradeLabels[terms.grade]}`}</dd>
</div>
<div className={styles.fact}>
<dt>Тип предложения</dt>
<dd>{offerTypeLabels[terms.offer_type]}</dd>
</div>
<div className={styles.fact}>
<dt>Задачи</dt>
<dd>
<ul className={styles.list}>
{terms.tasks.map((task, index) => (
<li key={`${index}-${task}`}>{task}</li>
))}
</ul>
</dd>
</div>
<div className={styles.fact}>
<dt>Команда</dt>
<dd className={styles.multiline}>{terms.team}</dd>
</div>
<div className={styles.fact}>
<dt>Технологии</dt>
<dd>{terms.tech_stack.join(", ")}</dd>
</div>
<div className={styles.fact}>
<dt>Формат работы</dt>
<dd>{terms.work_formats.map((format) => workFormatLabels[format]).join(", ")}</dd>
</div>
<div className={styles.fact}>
<dt>Место работы</dt>
<dd>{location}</dd>
</div>
<div className={styles.fact}>
<dt>Зарплатная вилка</dt>
<dd data-term="salary">{formatSalaryRange(terms.salary)}</dd>
</div>
<div className={styles.fact}>
<dt>Способ связи после принятия</dt>
<dd data-term="communication">
{communicationChannelLabels[terms.communication_method.channel]}
{terms.communication_method.details
? `. ${terms.communication_method.details}`
: null}
</dd>
</div>
<div className={styles.fact}>
<dt>Пакет</dt>
<dd>
<dl className={styles.package}>
{packageItemKeys.map((key) => {
const item = terms.package[key];
return (
<div key={key} className={styles.fact} data-package={key}>
<dt>{packageItemLabels[key]}</dt>
<dd>{item.status === "provided" ? item.description : notProvidedLabel}</dd>
</div>
);
})}
</dl>
</dd>
</div>
<div className={styles.fact}>
<dt>Срок ответа</dt>
<dd>
{responseDeadlineAt ? (
<>
{"До "}
<time dateTime={responseDeadlineAt}>
{formatServerMoment(responseDeadlineAt)}
</time>
</>
) : (
`${responsePeriodLabel(responsePeriodDays)} с момента доставки`
)}
</dd>
</div>
</dl>
</article>
<InvitationTermsArticle
terms={terms}
responsePeriodDays={responsePeriodDays}
responseDeadlineAt={responseDeadlineAt}
/>
</div>
);
}
@@ -0,0 +1,52 @@
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it } from "vitest";
import { candidateTerms, openDeadline } from "../../../entities/invitation/testing";
import { InvitationTermsArticle } from "./invitation-terms";
describe("invitation terms article", () => {
it("shows the server deadline with its UTC label when the invitation is delivered", () => {
const html = renderToStaticMarkup(
<InvitationTermsArticle
terms={candidateTerms}
responsePeriodDays={null}
responseDeadlineAt={openDeadline}
/>,
);
expect(html).toMatch(/<dt>Срок ответа<\/dt><dd>До <time dateTime="2099-10-16T10:00:00Z">/);
expect(html).toMatch(/UTC<\/time>/);
});
it("shows the answer period for an unsent draft and no deadline row without either", () => {
const draft = renderToStaticMarkup(
<InvitationTermsArticle
terms={candidateTerms}
responsePeriodDays={7}
responseDeadlineAt={null}
/>,
);
expect(draft).toContain("7 дней с момента доставки");
const bare = renderToStaticMarkup(
<InvitationTermsArticle
terms={candidateTerms}
responsePeriodDays={null}
responseDeadlineAt={null}
/>,
);
expect(bare).not.toContain("Срок ответа");
});
it("uses the heading level of the page outline", () => {
const html = renderToStaticMarkup(
<InvitationTermsArticle
terms={candidateTerms}
responsePeriodDays={null}
responseDeadlineAt={null}
headingLevel={3}
/>,
);
expect(html).toMatch(/<h3 class="[^"]*">Middle Go-разработчик/);
});
});
@@ -0,0 +1,130 @@
import type { InvitationTerms } from "../../../shared/api/schemas";
import {
communicationChannelLabels,
formatSalaryRange,
formatServerMoment,
notProvidedLabel,
offerTypeLabels,
packageItemKeys,
packageItemLabels,
responsePeriodLabel,
} from "../../../entities/invitation";
import { gradeLabels, specializationLabels, workFormatLabels } from "../../../entities/match";
import styles from "./invitation-preview.module.css";
type InvitationTermsArticleProps = {
terms: InvitationTerms;
/**
* Days to answer, shown while no deadline exists yet (an unsent draft).
* Null when the server deadline is shown instead.
*/
responsePeriodDays: number | null;
/** The server deadline once the invitation is delivered; null for an unsent draft. */
responseDeadlineAt: string | null;
/** The role name is a heading below the section title; the page outline sets its level. */
headingLevel?: 3 | 4;
};
/**
* Every term of an invitation, as the candidate sees it: each package
* condition with its description or as explicitly not provided, the salary
* range with its tax basis, and the answer deadline. It renders data only.
* Both the organization preview and the candidate's invitation use it.
*/
export function InvitationTermsArticle({
terms,
responsePeriodDays,
responseDeadlineAt,
headingLevel = 4,
}: InvitationTermsArticleProps) {
const location =
terms.location ??
(terms.work_formats.every((format) => format === "remote")
? "Не требуется: только удаленная работа"
: "Не указано");
const RoleHeading = headingLevel === 3 ? "h3" : "h4";
const responseLine =
responseDeadlineAt !== null ? (
<>
{"До "}
<time dateTime={responseDeadlineAt}>{formatServerMoment(responseDeadlineAt)}</time>
</>
) : responsePeriodDays !== null ? (
`${responsePeriodLabel(responsePeriodDays)} с момента доставки`
) : null;
return (
<article className={styles.terms} aria-label="Условия приглашения">
<RoleHeading className={styles.role}>{terms.role_title}</RoleHeading>
<dl className={styles.facts}>
<div className={styles.fact}>
<dt>Специализация и грейд</dt>
<dd>{`${specializationLabels[terms.specialization]}, ${gradeLabels[terms.grade]}`}</dd>
</div>
<div className={styles.fact}>
<dt>Тип предложения</dt>
<dd>{offerTypeLabels[terms.offer_type]}</dd>
</div>
<div className={styles.fact}>
<dt>Задачи</dt>
<dd>
<ul className={styles.list}>
{terms.tasks.map((task, index) => (
<li key={`${index}-${task}`}>{task}</li>
))}
</ul>
</dd>
</div>
<div className={styles.fact}>
<dt>Команда</dt>
<dd className={styles.multiline}>{terms.team}</dd>
</div>
<div className={styles.fact}>
<dt>Технологии</dt>
<dd>{terms.tech_stack.join(", ")}</dd>
</div>
<div className={styles.fact}>
<dt>Формат работы</dt>
<dd>{terms.work_formats.map((format) => workFormatLabels[format]).join(", ")}</dd>
</div>
<div className={styles.fact}>
<dt>Место работы</dt>
<dd>{location}</dd>
</div>
<div className={styles.fact}>
<dt>Зарплатная вилка</dt>
<dd data-term="salary">{formatSalaryRange(terms.salary)}</dd>
</div>
<div className={styles.fact}>
<dt>Способ связи после принятия</dt>
<dd data-term="communication">
{communicationChannelLabels[terms.communication_method.channel]}
{terms.communication_method.details ? `. ${terms.communication_method.details}` : null}
</dd>
</div>
<div className={styles.fact}>
<dt>Пакет</dt>
<dd>
<dl className={styles.package}>
{packageItemKeys.map((key) => {
const item = terms.package[key];
return (
<div key={key} className={styles.fact} data-package={key}>
<dt>{packageItemLabels[key]}</dt>
<dd>{item.status === "provided" ? item.description : notProvidedLabel}</dd>
</div>
);
})}
</dl>
</dd>
</div>
{responseLine !== null ? (
<div className={styles.fact}>
<dt>Срок ответа</dt>
<dd>{responseLine}</dd>
</div>
) : null}
</dl>
</article>
);
}