fix(ux): preserve localized save errors and current language retries
This commit is contained in:
@@ -39,6 +39,7 @@ export default function CompaniesTable() {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const [editError, setEditError] = useState("");
|
||||
const [editing, setEditing] = useState<Company | null>(null);
|
||||
const [relationshipOpen, setRelationshipOpen] = useState(false);
|
||||
const [relationshipLoading, setRelationshipLoading] = useState(false);
|
||||
@@ -78,6 +79,7 @@ export default function CompaniesTable() {
|
||||
}, [companies, location.pathname, location.search, navigate]);
|
||||
|
||||
const openEdit = (c: Company) => {
|
||||
setEditError("");
|
||||
setEditing(c);
|
||||
setRecruiterName(c.recruiterName ?? "");
|
||||
setRecruiterEmail(c.recruiterEmail ?? "");
|
||||
@@ -104,6 +106,7 @@ export default function CompaniesTable() {
|
||||
|
||||
const save = async () => {
|
||||
if (!editing?.id) return;
|
||||
setEditError("");
|
||||
try {
|
||||
const res = await api.put<Company>(`/companies/${editing.id}`, {
|
||||
name: editing.name,
|
||||
@@ -122,7 +125,7 @@ export default function CompaniesTable() {
|
||||
setEditOpen(false);
|
||||
setEditing(null);
|
||||
} catch (error) {
|
||||
toast(getApiErrorMessage(error, t("companiesUpdateFailed")), "error");
|
||||
setEditError(getApiErrorMessage(error, t("companiesUpdateFailed")));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -166,7 +169,7 @@ export default function CompaniesTable() {
|
||||
{renderCompanyMeta(t("companiesSource"), c.source)}
|
||||
{renderCompanyMeta(t("companiesPipeline"), c.pipelineStage)}
|
||||
{renderCompanyMeta(t("companiesRecruiter"), [c.recruiterName, c.recruiterEmail].filter(Boolean).join(" · "))}
|
||||
{renderCompanyMeta(t("companiesNextContact"), c.nextContactAt ? new Date(c.nextContactAt).toLocaleDateString() : null)}
|
||||
{renderCompanyMeta(t("companiesNextContact"), c.nextContactAt ? new Date(c.nextContactAt).toLocaleDateString(language === "nb" ? "nb-NO" : "en") : null)}
|
||||
</Box>
|
||||
</Stack>
|
||||
</Paper>
|
||||
@@ -202,7 +205,7 @@ export default function CompaniesTable() {
|
||||
{c.recruiterName ?? ""}
|
||||
{c.recruiterEmail ? ` (${c.recruiterEmail})` : ""}
|
||||
</TableCell>
|
||||
<TableCell>{c.nextContactAt ? new Date(c.nextContactAt).toLocaleDateString() : ""}</TableCell>
|
||||
<TableCell>{c.nextContactAt ? new Date(c.nextContactAt).toLocaleDateString(language === "nb" ? "nb-NO" : "en") : ""}</TableCell>
|
||||
<TableCell align="right">
|
||||
<IconButton size="small" aria-label={`${t("companiesRelationship")}: ${c.name}`} onClick={() => void openRelationship(c)}>
|
||||
<PeopleAltOutlinedIcon fontSize="small" />
|
||||
@@ -231,6 +234,7 @@ export default function CompaniesTable() {
|
||||
<Dialog open={editOpen} onClose={() => setEditOpen(false)} fullWidth fullScreen={isMobile} maxWidth="sm">
|
||||
<DialogTitle>{t("companiesEdit")}</DialogTitle>
|
||||
<DialogContent>
|
||||
{editError ? <Alert severity="error" sx={{ mt: 1 }}>{editError}</Alert> : null}
|
||||
<Box sx={{ display: "grid", gridTemplateColumns: { xs: "1fr", md: "1fr 1fr" }, gap: 2, mt: 1 }}>
|
||||
<TextField
|
||||
label={t("companiesName")}
|
||||
|
||||
Reference in New Issue
Block a user