update all page to refresh immidiately without clicking sync button or refreshing the whole page

This commit is contained in:
Alberto-Audrix committed 2026-10-07 11:17:44 +07:00
1 parent d5b0c12c40
commit 83a41fbbcb
15 files changed
+490 -151

No files matched your search

@@ -11,6 +11,7 @@ type Props = {
cycleId: number;
currentDay: number;
readOnly?: boolean;
onSaved?: (savedRow: ManualInput) => void | Promise<void>;
};
type FormState = {
@@ -52,7 +53,12 @@ function toForm(row: ManualInput): FormState {
};
}
const DashboardManualInputForm: React.FC<Props> = ({ cycleId, currentDay, readOnly = false }) => {
const DashboardManualInputForm: React.FC<Props> = ({
cycleId,
currentDay,
readOnly = false,
onSaved,
}) => {
const [form, setForm] = useState<FormState>(() => emptyForm(currentDay));
const [saved, setSaved] = useState<ManualInput | null>(null);
const [rows, setRows] = useState<ManualInput[]>([]);
@@ -138,6 +144,13 @@ const DashboardManualInputForm: React.FC<Props> = ({ cycleId, currentDay, readOn
return [row, ...others];
});
setNotice('Input manual tersimpan.');
if (onSaved) {
try {
await onSaved(row);
} catch {
// Non-blocking if parent refresh fails
}
}
} catch (err) {
setError(errorMessage(err));
} finally {
@@ -82,4 +82,23 @@ describe('DashboardManualInputForm', () => {
expect(body).not.toHaveProperty('fcr_manual');
expect(body).not.toHaveProperty('eef_manual');
});
it('calls onSaved callback when manual input is successfully saved', async () => {
const onSavedMock = vi.fn();
render(<DashboardManualInputForm cycleId={4} currentDay={10} onSaved={onSavedMock} />);
expect(await screen.findByRole('heading', { name: /Input manual/i })).toBeInTheDocument();
fireEvent.change(screen.getByLabelText(/Mortalitas/i), { target: { value: '5' } });
fireEvent.click(screen.getByRole('button', { name: /Simpan/i }));
await waitFor(() => expect(createMock).toHaveBeenCalledTimes(1));
await waitFor(() => expect(onSavedMock).toHaveBeenCalledTimes(1));
expect(onSavedMock).toHaveBeenCalledWith(
expect.objectContaining({
id: 1,
cycle: 4,
mortality_manual: 5,
})
);
});
});