Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

Commit

Permalink
chore: rename all reducers actions and payload variables
Browse files Browse the repository at this point in the history
  • Loading branch information
pfferrari committed Mar 21, 2023
1 parent 98857a9 commit ca5b897
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 34 deletions.
6 changes: 3 additions & 3 deletions packages/app-webhooks/src/components/Delete/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export function WebhookDeleteProvider({

const fetchWebhook = useCallback(async () => {
try {
const webhookDelete = await sdkClient.webhooks.retrieve(webhookId)
dispatch({ type: 'loadData', payload: webhookDelete })
const webhook = await sdkClient.webhooks.retrieve(webhookId)
dispatch({ type: 'webhook/loaded', payload: webhook })
} catch {
dispatch({ type: 'setNotFound' })
dispatch({ type: 'webhook/onError' })
}
}, [webhookId])

Expand Down
8 changes: 5 additions & 3 deletions packages/app-webhooks/src/components/Delete/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { Webhook } from '@commercelayer/sdk'
import { WebhookDeleteContextState } from 'App'

type Action = { type: 'loadData'; payload: Webhook } | { type: 'setNotFound' }
type Action =
| { type: 'webhook/loaded'; payload: Webhook }
| { type: 'webhook/onError' }

export const reducer = (
state: WebhookDeleteContextState,
action: Action
): WebhookDeleteContextState | never => {
switch (action.type) {
case 'loadData':
case 'webhook/loaded':
return {
...state,
data: action.payload,
isLoading: false
}
case 'setNotFound':
case 'webhook/onError':
return {
...state,
isNotFound: true,
Expand Down
6 changes: 3 additions & 3 deletions packages/app-webhooks/src/components/Details/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export function WebhookDetailsProvider({
const webhook = await sdkClient.webhooks.retrieve(webhookId, {
include: ['last_event_callbacks']
})
dispatch({ type: 'loadData', payload: webhook })
dispatch({ type: 'webhook/loaded', payload: webhook })
} catch {
dispatch({ type: 'setNotFound' })
dispatch({ type: 'webhook/onError' })
}
}, [webhookId])

Expand All @@ -48,7 +48,7 @@ export function WebhookDetailsProvider({
}
)
.then((webhook) => {
dispatch({ type: 'loadData', payload: webhook })
dispatch({ type: 'webhook/loaded', payload: webhook })
})
.catch(() => {})
}, [webhookId])
Expand Down
8 changes: 5 additions & 3 deletions packages/app-webhooks/src/components/Details/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { Webhook } from '@commercelayer/sdk'
import { WebhookDetailsContextState } from 'App'

type Action = { type: 'loadData'; payload: Webhook } | { type: 'setNotFound' }
type Action =
| { type: 'webhook/loaded'; payload: Webhook }
| { type: 'webhook/onError' }

export const reducer = (
state: WebhookDetailsContextState,
action: Action
): WebhookDetailsContextState | never => {
switch (action.type) {
case 'loadData':
case 'webhook/loaded':
return {
...state,
data: action.payload,
isLoading: false
}
case 'setNotFound':
case 'webhook/onError':
return {
...state,
isNotFound: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export function ListEventCallbackProvider({
const [state, dispatch] = useReducer(reducer, initialState)

const changePage = useCallback(
(page: number) => dispatch({ type: 'changePage', payload: page }),
(page: number) =>
dispatch({ type: 'eventCallbacks/changePage', payload: page }),
[]
)

Expand All @@ -49,7 +50,7 @@ export function ListEventCallbackProvider({
webhookId,
pageSize
})
dispatch({ type: 'loadData', payload: eventCallbacks })
dispatch({ type: 'eventCallbacks/loaded', payload: eventCallbacks })
}
}, [webhookId, state.currentPage])

Expand Down
12 changes: 6 additions & 6 deletions packages/app-webhooks/src/components/EventCallbacks/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ import { ListResponse } from '@commercelayer/sdk/lib/cjs/resource'
import { ListEventCallbackContextState } from 'App'

type Action =
| { type: 'loadData'; payload: ListResponse<EventCallback> }
| { type: 'changePage'; payload: number }
| { type: 'sort'; payload: 'asc' | 'desc' }
| { type: 'eventCallbacks/loaded'; payload: ListResponse<EventCallback> }
| { type: 'eventCallbacks/changePage'; payload: number }
| { type: 'eventCallbacks/changeSort'; payload: 'asc' | 'desc' }

export const reducer = (
state: ListEventCallbackContextState,
action: Action
): ListEventCallbackContextState => {
switch (action.type) {
case 'loadData':
case 'eventCallbacks/loaded':
return {
...state,
list: action.payload,
isLoading: false
}
case 'changePage':
case 'eventCallbacks/changePage':
return {
...state,
currentPage: action.payload,
isLoading: true
}
case 'sort':
case 'eventCallbacks/changeSort':
return {
...state,
sort: {
Expand Down
6 changes: 3 additions & 3 deletions packages/app-webhooks/src/components/Form/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export function WebhookFormProvider({

const fetchJob = useCallback(async () => {
try {
const webhookForm = await sdkClient.webhooks.retrieve(webhookId)
dispatch({ type: 'loadData', payload: webhookForm })
const webhook = await sdkClient.webhooks.retrieve(webhookId)
dispatch({ type: 'webhook/loaded', payload: webhook })
} catch {
dispatch({ type: 'setNotFound' })
dispatch({ type: 'webhook/onError' })
}
}, [webhookId])

Expand Down
8 changes: 5 additions & 3 deletions packages/app-webhooks/src/components/Form/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { Webhook } from '@commercelayer/sdk'
import { WebhookFormContextState } from 'App'

type Action = { type: 'setNotFound' } | { type: 'loadData'; payload: Webhook }
type Action =
| { type: 'webhook/onError' }
| { type: 'webhook/loaded'; payload: Webhook }

export const reducer = (
state: WebhookFormContextState,
action: Action
): WebhookFormContextState | never => {
switch (action.type) {
case 'setNotFound':
case 'webhook/onError':
return {
...state,
isNotFound: true,
isLoading: false
}
case 'loadData':
case 'webhook/loaded':
return {
...state,
data: action.payload,
Expand Down
4 changes: 2 additions & 2 deletions packages/app-webhooks/src/components/List/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function ListWebhookProvider({
const [state, dispatch] = useReducer(reducer, initialState)

const changePage = useCallback(
(page: number) => dispatch({ type: 'changePage', payload: page }),
(page: number) => dispatch({ type: 'webhooks/changePage', payload: page }),
[]
)

Expand All @@ -41,7 +41,7 @@ export function ListWebhookProvider({
state,
pageSize
})
dispatch({ type: 'loadData', payload: webhooks })
dispatch({ type: 'webhooks/loaded', payload: webhooks })
}, [state.currentPage])

useEffect(
Expand Down
12 changes: 6 additions & 6 deletions packages/app-webhooks/src/components/List/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ import { ListResponse } from '@commercelayer/sdk/lib/cjs/resource'
import { ListWebhookContextState } from 'App'

type Action =
| { type: 'loadData'; payload: ListResponse<Webhook> }
| { type: 'changePage'; payload: number }
| { type: 'sort'; payload: 'asc' | 'desc' }
| { type: 'webhooks/loaded'; payload: ListResponse<Webhook> }
| { type: 'webhooks/changePage'; payload: number }
| { type: 'webhooks/changeSort'; payload: 'asc' | 'desc' }

export const reducer = (
state: ListWebhookContextState,
action: Action
): ListWebhookContextState => {
switch (action.type) {
case 'loadData':
case 'webhooks/loaded':
return {
...state,
list: action.payload,
isLoading: false
}
case 'changePage':
case 'webhooks/changePage':
return {
...state,
currentPage: action.payload,
isLoading: true
}
case 'sort':
case 'webhooks/changeSort':
return {
...state,
sort: {
Expand Down

0 comments on commit ca5b897

Please sign in to comment.