Skip to content

Commit 5de4e64

Browse files
committed
chore: pr feedback
1 parent 3d605e9 commit 5de4e64

20 files changed

+79
-90
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { PaymentFlowProps } from './PaymentFlowComponents'
2+
import { PaymentFlow } from './Flow'
3+
import type { BaseComponentInterface } from '@/components/Base/Base'
4+
import { BaseComponent } from '@/components/Base/Base'
5+
6+
export function ContractorPayments(props: PaymentFlowProps & BaseComponentInterface) {
7+
return (
8+
<BaseComponent {...props}>
9+
<PaymentFlow {...props} />
10+
</BaseComponent>
11+
)
12+
}

src/components/ContractorPayment/Flow/Flow.stories.tsx renamed to src/components/Contractor/Payments/Flow/Flow.stories.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import type { StoryDefault, Story } from '@ladle/react'
22
import { action } from '@ladle/react'
3-
import { ContractorPayment } from './ContractorPayment'
3+
import { ContractorPayments } from './ContractorPayments'
44

55
export default {
6-
title: 'Domain/ContractorPayment/Complete Flow',
6+
title: 'Domain/Contractor/Payments/Complete Flow',
77
} satisfies StoryDefault
88

99
export const CompleteFlow: Story = () => {
10-
return <ContractorPayment companyId="test-company-123" onEvent={action('onEvent')} />
10+
return <ContractorPayments companyId="test-company-123" onEvent={action('onEvent')} />
1111
}
1212

1313
CompleteFlow.meta = {
@@ -16,7 +16,7 @@ CompleteFlow.meta = {
1616
}
1717

1818
export const WithDifferentCompany: Story = () => {
19-
return <ContractorPayment companyId="different-company-456" onEvent={action('onEvent')} />
19+
return <ContractorPayments companyId="different-company-456" onEvent={action('onEvent')} />
2020
}
2121

2222
WithDifferentCompany.meta = {
@@ -26,7 +26,7 @@ WithDifferentCompany.meta = {
2626
export const MobileView: Story = () => {
2727
return (
2828
<div style={{ maxWidth: '375px', margin: '0 auto' }}>
29-
<ContractorPayment companyId="test-company-123" onEvent={action('onEvent')} />
29+
<ContractorPayments companyId="test-company-123" onEvent={action('onEvent')} />
3030
</div>
3131
)
3232
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { createMachine } from 'robot3'
2+
import { useMemo } from 'react'
3+
import { paymentMachine } from './paymentStateMachine'
4+
import type { PaymentFlowProps, PaymentFlowContextInterface } from './PaymentFlowComponents'
5+
import { PaymentHistoryContextual } from './PaymentFlowComponents'
6+
import { Flow } from '@/components/Flow/Flow'
7+
8+
export const PaymentFlow = ({ companyId, onEvent, defaultValues }: PaymentFlowProps) => {
9+
const flow = useMemo(
10+
() =>
11+
createMachine(
12+
'paymentHistory',
13+
paymentMachine,
14+
(initialContext: PaymentFlowContextInterface) => ({
15+
...initialContext,
16+
component: PaymentHistoryContextual,
17+
companyId,
18+
defaultValues,
19+
}),
20+
),
21+
[companyId, defaultValues],
22+
)
23+
return <Flow machine={flow} onEvent={onEvent} />
24+
}

src/components/ContractorPayment/Flow/ContractorPaymentFlowComponents.tsx renamed to src/components/Contractor/Payments/Flow/PaymentFlowComponents.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ import { ensureRequired } from '@/helpers/ensureRequired'
1010
import { componentEvents } from '@/shared/constants'
1111
import { formatDateNamedWeekdayShortPlusDate } from '@/helpers/dateFormatting'
1212

13-
export type ContractorPaymentFlowDefaultValues = Record<string, unknown>
13+
export type PaymentFlowDefaultValues = Record<string, unknown>
1414

15-
export interface ContractorPaymentFlowProps extends BaseComponentInterface {
15+
export interface PaymentFlowProps extends BaseComponentInterface {
1616
companyId: string
17-
defaultValues?: ContractorPaymentFlowDefaultValues
17+
defaultValues?: PaymentFlowDefaultValues
1818
}
1919

20-
export interface ContractorPaymentFlowContextInterface extends FlowContextInterface {
20+
export interface PaymentFlowContextInterface extends FlowContextInterface {
2121
companyId: string
2222
paymentGroupId?: string
2323
selectedDate?: string
24-
defaultValues?: ContractorPaymentFlowDefaultValues
24+
defaultValues?: PaymentFlowDefaultValues
2525
}
2626

27-
export function ContractorPaymentPaymentHistoryContextual() {
28-
const { onEvent } = useFlow<ContractorPaymentFlowContextInterface>()
27+
export function PaymentHistoryContextual() {
28+
const { onEvent } = useFlow<PaymentFlowContextInterface>()
2929
const [showData, setShowData] = useState(false)
3030

3131
const mockHistory = [
@@ -54,8 +54,8 @@ export function ContractorPaymentPaymentHistoryContextual() {
5454
)
5555
}
5656

57-
export function ContractorPaymentCreatePaymentContextual() {
58-
const { onEvent } = useFlow<ContractorPaymentFlowContextInterface>()
57+
export function CreatePaymentContextual() {
58+
const { onEvent } = useFlow<PaymentFlowContextInterface>()
5959
const [contractors] = useState<ContractorPaymentForGroup[]>([
6060
{
6161
uuid: '1',
@@ -110,13 +110,13 @@ export function ContractorPaymentCreatePaymentContextual() {
110110
)
111111
}
112112

113-
export function ContractorPaymentEditContextual() {
113+
export function PaymentEditContextual() {
114114
// TODO: PLACEHOLDER - Implement flow state machine to pass contractor data
115115
return null
116116
}
117117

118-
export function ContractorPaymentOverviewContextual() {
119-
const { onEvent } = useFlow<ContractorPaymentFlowContextInterface>()
118+
export function OverviewContextual() {
119+
const { onEvent } = useFlow<PaymentFlowContextInterface>()
120120

121121
// TODO: PLACEHOLDER - Replace with actual contractor payment group from API
122122
const mockContractorPaymentGroup: ContractorPaymentGroup = {
@@ -182,8 +182,8 @@ export function ContractorPaymentOverviewContextual() {
182182
)
183183
}
184184

185-
export function ContractorPaymentDetailContextual() {
186-
const { selectedDate, onEvent } = useFlow<ContractorPaymentFlowContextInterface>()
185+
export function DetailContextual() {
186+
const { selectedDate, onEvent } = useFlow<PaymentFlowContextInterface>()
187187

188188
const mockPayments = [
189189
{

src/components/ContractorPayment/Flow/contractorPaymentStateMachine.ts renamed to src/components/Contractor/Payments/Flow/paymentStateMachine.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { transition, reduce, state } from 'robot3'
22
import {
3-
ContractorPaymentPaymentHistoryContextual,
4-
ContractorPaymentCreatePaymentContextual,
5-
ContractorPaymentOverviewContextual,
6-
} from './ContractorPaymentFlowComponents'
3+
PaymentHistoryContextual,
4+
CreatePaymentContextual,
5+
OverviewContextual,
6+
} from './PaymentFlowComponents'
77
import { componentEvents } from '@/shared/constants'
88
import type { MachineEventType, MachineTransition } from '@/types/Helpers'
99
import type { FlowContextInterface } from '@/components/Flow/useFlow'
@@ -21,27 +21,27 @@ type EventPayloads = {
2121
[componentEvents.BACK_TO_LIST]: undefined
2222
}
2323

24-
export interface ContractorPaymentFlowContextInterface extends FlowContextInterface {
24+
export interface PaymentFlowContextInterface extends FlowContextInterface {
2525
companyId: string
2626
paymentGroupId?: string
2727
selectedDate?: string
2828
}
2929

3030
const createReducer =
31-
(overrides: Partial<ContractorPaymentFlowContextInterface>) =>
32-
(ctx: ContractorPaymentFlowContextInterface): ContractorPaymentFlowContextInterface => ({
31+
(overrides: Partial<PaymentFlowContextInterface>) =>
32+
(ctx: PaymentFlowContextInterface): PaymentFlowContextInterface => ({
3333
...ctx,
3434
...overrides,
3535
})
3636

37-
export const contractorPaymentMachine = {
37+
export const paymentMachine = {
3838
paymentHistory: state<MachineTransition>(
3939
transition(
4040
componentEvents.CREATE_PAYMENT_SELECTED,
4141
'createPayment',
4242
reduce(
4343
createReducer({
44-
component: ContractorPaymentCreatePaymentContextual,
44+
component: CreatePaymentContextual,
4545
}),
4646
),
4747
),
@@ -52,11 +52,11 @@ export const contractorPaymentMachine = {
5252
'overview',
5353
reduce(
5454
(
55-
ctx: ContractorPaymentFlowContextInterface,
55+
ctx: PaymentFlowContextInterface,
5656
ev: MachineEventType<EventPayloads, typeof componentEvents.PAYMENT_CONFIGURED>,
57-
): ContractorPaymentFlowContextInterface => ({
57+
): PaymentFlowContextInterface => ({
5858
...ctx,
59-
component: ContractorPaymentOverviewContextual,
59+
component: OverviewContextual,
6060
paymentGroupId: ev.payload.paymentGroupId,
6161
}),
6262
),
@@ -66,7 +66,7 @@ export const contractorPaymentMachine = {
6666
'paymentHistory',
6767
reduce(
6868
createReducer({
69-
component: ContractorPaymentPaymentHistoryContextual,
69+
component: PaymentHistoryContextual,
7070
}),
7171
),
7272
),
@@ -77,7 +77,7 @@ export const contractorPaymentMachine = {
7777
'createPayment',
7878
reduce(
7979
createReducer({
80-
component: ContractorPaymentCreatePaymentContextual,
80+
component: CreatePaymentContextual,
8181
}),
8282
),
8383
),
@@ -86,7 +86,7 @@ export const contractorPaymentMachine = {
8686
'paymentHistory',
8787
reduce(
8888
createReducer({
89-
component: ContractorPaymentPaymentHistoryContextual,
89+
component: PaymentHistoryContextual,
9090
}),
9191
),
9292
),
@@ -96,9 +96,9 @@ export const contractorPaymentMachine = {
9696
componentEvents.BACK_TO_LIST,
9797
'paymentHistory',
9898
reduce(
99-
(ctx: ContractorPaymentFlowContextInterface): ContractorPaymentFlowContextInterface => ({
99+
(ctx: PaymentFlowContextInterface): PaymentFlowContextInterface => ({
100100
...ctx,
101-
component: ContractorPaymentPaymentHistoryContextual,
101+
component: PaymentHistoryContextual,
102102
selectedDate: undefined,
103103
}),
104104
),

0 commit comments

Comments
 (0)