Compare commits
1 Commits
fix/storyb
...
main
Author | SHA1 | Date | |
---|---|---|---|
bae2ebf22a |
@ -1,12 +1,11 @@
|
||||
import CreateRandomInvoiceButtonVM from "@/app/[lang]/dashboard/vm/create-random-invoice-button-vm";
|
||||
import di from "@/bootstrap/di/init-di";
|
||||
import createInvoiceUsecase from "@/feature/core/invoice/domain/usecase/create-invoice/create-invoice-impl.usecase";
|
||||
import { createInvoiceUsecaseKey } from "@/feature/core/invoice/domain/usecase/create-invoice/create-invoice.usecase";
|
||||
import createInvoiceUsecase from "@/feature/core/invoice/domain/usecase/create-invoice-usecase";
|
||||
|
||||
export default function dashboardAppModule() {
|
||||
const dashboardDi = di.createChildContainer();
|
||||
|
||||
dashboardDi.register(createInvoiceUsecaseKey, {
|
||||
dashboardDi.register(createInvoiceUsecase.name, {
|
||||
useValue: createInvoiceUsecase,
|
||||
});
|
||||
dashboardDi.register(
|
||||
|
@ -4,20 +4,17 @@ import useThrottle from "@/bootstrap/helpers/hooks/use-throttle";
|
||||
import BaseVM from "@/bootstrap/helpers/vm/base-vm";
|
||||
import langKey from "@/bootstrap/i18n/dictionaries/lang-key";
|
||||
import { InvoiceParam } from "@/feature/core/invoice/domain/param/invoice-param";
|
||||
import {
|
||||
CreateInvoiceUsecase,
|
||||
createInvoiceUsecaseKey,
|
||||
} from "@/feature/core/invoice/domain/usecase/create-invoice/create-invoice.usecase";
|
||||
import createInvoiceUsecase from "@/feature/core/invoice/domain/usecase/create-invoice-usecase";
|
||||
import { faker } from "@faker-js/faker";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
export default class CreateRandomInvoiceButtonVM extends BaseVM<ButtonVm> {
|
||||
private createInvoice: CreateInvoiceUsecase;
|
||||
private createInvoice: typeof createInvoiceUsecase;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.createInvoice = this.di.resolve(createInvoiceUsecaseKey);
|
||||
this.createInvoice = this.di.resolve(createInvoiceUsecase.name);
|
||||
}
|
||||
|
||||
useVM(): ButtonVm {
|
||||
|
@ -4,7 +4,7 @@ import { DiContext, useDI } from "@/bootstrap/di/di-context";
|
||||
import mockedModuleDi from "@/bootstrap/di/mocked-module-di";
|
||||
import Story from "@/bootstrap/helpers/view/storybook-base-template-type";
|
||||
import getArgVM from "@/bootstrap/helpers/view/storybook-with-arg-vm";
|
||||
import { createInvoiceUsecaseKey } from "@/feature/core/invoice/domain/usecase/create-invoice/create-invoice.usecase";
|
||||
import createInvoiceUsecase from "@/feature/core/invoice/domain/usecase/create-invoice-usecase";
|
||||
import type { Meta } from "@storybook/react";
|
||||
import { useRef } from "react";
|
||||
|
||||
@ -36,32 +36,30 @@ export const Primary: Story = {
|
||||
export const WithVM: Story = {
|
||||
decorators: [
|
||||
(Story) => {
|
||||
const di = useRef(
|
||||
mockedModuleDi([
|
||||
{
|
||||
token: CreateRandomInvoiceButtonVM,
|
||||
provider: CreateRandomInvoiceButtonVM,
|
||||
},
|
||||
{
|
||||
token: createInvoiceUsecaseKey,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, no-console
|
||||
provider: (args: any) => console.log("clicked", args),
|
||||
},
|
||||
]),
|
||||
);
|
||||
return (
|
||||
<DiContext.Provider value={di.current}>
|
||||
<Story di={di.current} />
|
||||
</DiContext.Provider>
|
||||
);
|
||||
const di = mockedModuleDi([
|
||||
{
|
||||
token: CreateRandomInvoiceButtonVM,
|
||||
provider: CreateRandomInvoiceButtonVM,
|
||||
},
|
||||
{
|
||||
token: createInvoiceUsecase.name,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, no-console
|
||||
provider: (args: any) => console.log("clicked", args),
|
||||
},
|
||||
]);
|
||||
return <Story di={di} />;
|
||||
},
|
||||
],
|
||||
render: () => {
|
||||
render: (_, globalProps) => {
|
||||
function Child() {
|
||||
const di = useDI();
|
||||
const vm = useRef(di.resolve(CreateRandomInvoiceButtonVM));
|
||||
return <Button vm={vm.current} memoizedByVM={false} />;
|
||||
}
|
||||
return <Child />;
|
||||
return (
|
||||
<DiContext.Provider value={globalProps.di}>
|
||||
<Child />
|
||||
</DiContext.Provider>
|
||||
);
|
||||
},
|
||||
};
|
||||
|
@ -1,3 +1,5 @@
|
||||
"use server";
|
||||
|
||||
import { ApiEither } from "@/feature/common/data/api-task";
|
||||
import ParamsFailure from "@/feature/common/failures/params-failure";
|
||||
import serverDi from "@/feature/common/server-di";
|
||||
@ -8,14 +10,13 @@ import {
|
||||
InvoiceParam,
|
||||
invoiceSchema,
|
||||
} from "@/feature/core/invoice/domain/param/invoice-param";
|
||||
import { CreateInvoiceUsecase } from "@/feature/core/invoice/domain/usecase/create-invoice/create-invoice.usecase";
|
||||
import { invoiceModuleKey } from "@/feature/core/invoice/invoice-module-key";
|
||||
import { pipe } from "fp-ts/lib/function";
|
||||
import { chain, fromNullable, left, map, right } from "fp-ts/lib/TaskEither";
|
||||
|
||||
const createInvoiceUsecase: CreateInvoiceUsecase = async (
|
||||
export default async function createInvoiceUsecase(
|
||||
params: InvoiceParam,
|
||||
): Promise<ApiEither<string>> => {
|
||||
): Promise<ApiEither<string>> {
|
||||
const repo = serverDi(invoiceModuleKey).resolve<InvoiceRepo>(invoiceRepoKey);
|
||||
|
||||
return pipe(
|
||||
@ -28,6 +29,4 @@ const createInvoiceUsecase: CreateInvoiceUsecase = async (
|
||||
}),
|
||||
chain((params) => repo.createInvoice(params)),
|
||||
)();
|
||||
};
|
||||
|
||||
export default createInvoiceUsecase;
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
import { ApiEither } from "@/feature/common/data/api-task";
|
||||
import { InvoiceParam } from "@/feature/core/invoice/domain/param/invoice-param";
|
||||
|
||||
export type CreateInvoiceUsecase = (
|
||||
param: InvoiceParam,
|
||||
) => Promise<ApiEither<string>>;
|
||||
|
||||
export const createInvoiceUsecaseKey = "createInvoiceUsecaseKey";
|
Loading…
x
Reference in New Issue
Block a user