refactor: enforce frontend view model boundaries
This commit is contained in:
@@ -9,9 +9,11 @@ import type { OperationValues } from "./OperationForm.types";
|
||||
import { OperationFormView } from "./OperationForm.view";
|
||||
|
||||
type ExampleProps = { conflict?: boolean; pending?: boolean };
|
||||
|
||||
const OperationExample: FC<ExampleProps> = (props) => {
|
||||
const [opened, setOpened] = useState(true);
|
||||
const [action, setAction] = useState("");
|
||||
|
||||
const methods = useForm<OperationValues>({
|
||||
defaultValues: {
|
||||
amount: "500",
|
||||
@@ -24,7 +26,9 @@ const OperationExample: FC<ExampleProps> = (props) => {
|
||||
targetCardId: "",
|
||||
},
|
||||
});
|
||||
|
||||
const kind = useWatch({ control: methods.control, name: "kind" });
|
||||
|
||||
return (
|
||||
<FormProvider {...methods}>
|
||||
<OperationFormView
|
||||
@@ -52,12 +56,12 @@ const OperationExample: FC<ExampleProps> = (props) => {
|
||||
validDate: value => value === "2026-08-01",
|
||||
}}
|
||||
latest={
|
||||
(props.conflict)
|
||||
? ({
|
||||
props.conflict
|
||||
? {
|
||||
details: "Учебная версия",
|
||||
onAdopt: () => setAction("Локальное принятие версии"),
|
||||
version: 2,
|
||||
})
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
loadingExpenses={false}
|
||||
@@ -69,7 +73,7 @@ const OperationExample: FC<ExampleProps> = (props) => {
|
||||
onNext={() => {}}
|
||||
onPrevious={() => {}}
|
||||
onReload={
|
||||
(props.conflict) ? () => setAction("Локальный reload") : undefined
|
||||
props.conflict ? () => setAction("Локальный reload") : undefined
|
||||
}
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
@@ -92,10 +96,12 @@ const OperationExample: FC<ExampleProps> = (props) => {
|
||||
saveDisabled={false}
|
||||
sourcePage={1}
|
||||
/>
|
||||
|
||||
<output aria-live="polite">{action}</output>
|
||||
</FormProvider>
|
||||
);
|
||||
};
|
||||
|
||||
const meta = {
|
||||
component: OperationExample,
|
||||
parameters: {
|
||||
@@ -109,8 +115,11 @@ const meta = {
|
||||
tags: ["autodocs"],
|
||||
title: "Product/OperationForm",
|
||||
} satisfies Meta<typeof OperationExample>;
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<typeof meta>;
|
||||
|
||||
export const Refund: Story = {};
|
||||
export const Pending: Story = { args: { pending: true } };
|
||||
export const Conflict: Story = { args: { conflict: true } };
|
||||
|
||||
Reference in New Issue
Block a user