2026-10-05 15:01:32 +00:00
|
|
|
import { Button } from "@repo/shadcn-ui/components/button";
|
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
|
|
2026-10-08 17:25:02 +00:00
|
|
|
import { MailFeedback } from "../../../mail-configurations/shared/ui/mail-feedback";
|
|
|
|
|
import { MailboxUseEditorDialog } from "../../../mailbox-uses";
|
2026-10-08 22:27:19 +00:00
|
|
|
import { useMailboxRelationsController } from "../controllers";
|
|
|
|
|
import type { MailboxRelationsProps } from "../types";
|
|
|
|
|
|
|
|
|
|
export function MailboxRelations(props: MailboxRelationsProps) {
|
2026-10-10 10:42:56 +00:00
|
|
|
const { company, mailboxId } = props;
|
2026-10-08 22:27:19 +00:00
|
|
|
const { editor, setEditor, query, uses, edited } = useMailboxRelationsController(props);
|
2026-10-05 15:01:32 +00:00
|
|
|
const { t } = useTranslation("companies");
|
2026-10-10 10:01:58 +00:00
|
|
|
|
2026-10-05 15:01:32 +00:00
|
|
|
return (
|
|
|
|
|
<section className="space-y-3 border-t pt-4">
|
|
|
|
|
<div className="flex items-center justify-between gap-3">
|
|
|
|
|
<h3 className="font-medium">{t("people")}</h3>
|
|
|
|
|
<Button onClick={() => setEditor("new")} size="sm" variant="outline">
|
|
|
|
|
{t("mailbox.linkPerson")}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
<MailFeedback error={query.error} />
|
|
|
|
|
<ul className="space-y-2">
|
|
|
|
|
{uses.map((item) => (
|
|
|
|
|
<li className="flex items-center justify-between gap-3 text-sm" key={item.id}>
|
|
|
|
|
<span>
|
|
|
|
|
{company.people.find((person) => person.id === item.values.personId)?.name ??
|
|
|
|
|
t("people")}{" "}
|
|
|
|
|
· {item.values.startDate} → {item.values.endDate ?? t("mailbox.openPeriod")}
|
|
|
|
|
</span>
|
|
|
|
|
{!item.values.endDate && (
|
|
|
|
|
<Button onClick={() => setEditor(item.id)} size="sm" variant="outline">
|
|
|
|
|
{t("mailbox.closeUse")}
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</li>
|
|
|
|
|
))}
|
|
|
|
|
</ul>
|
|
|
|
|
{editor && (
|
2026-10-08 14:43:34 +00:00
|
|
|
<MailboxUseEditorDialog
|
|
|
|
|
company={company}
|
|
|
|
|
mailboxId={mailboxId}
|
2026-10-05 15:01:32 +00:00
|
|
|
onOpenChange={(open) => {
|
|
|
|
|
if (!open) {
|
|
|
|
|
setEditor(undefined);
|
|
|
|
|
}
|
|
|
|
|
}}
|
2026-10-08 14:43:34 +00:00
|
|
|
onSaved={() => setEditor(undefined)}
|
|
|
|
|
use={edited}
|
|
|
|
|
/>
|
2026-10-05 15:01:32 +00:00
|
|
|
)}
|
|
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
}
|