Skip to content

Commit

Permalink
chore(router) update taxes :id name in router
Browse files Browse the repository at this point in the history
  • Loading branch information
ansmonjol committed Oct 18, 2023
1 parent db0e76e commit 93d04d3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
10 changes: 7 additions & 3 deletions src/components/taxes/TaxItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ interface TaxItemProps {

export const TaxItem = memo(({ deleteDialogRef, tax }: TaxItemProps) => {
const { translate } = useInternationalization()
const { id, name, code, rate } = tax
const { id: taxId, name, code, rate } = tax

return (
<ItemContainer>
<LocalListItemLink tabIndex={0} to={generatePath(UPDATE_TAX_ROUTE, { id })} data-test={code}>
<LocalListItemLink
tabIndex={0}
to={generatePath(UPDATE_TAX_ROUTE, { taxId })}
data-test={code}
>
<LeftSection>
<Avatar size="big" variant="connector">
<Icon size="medium" name="percentage" color="dark" />
Expand Down Expand Up @@ -95,7 +99,7 @@ export const TaxItem = memo(({ deleteDialogRef, tax }: TaxItemProps) => {
align: 'left',
fullWidth: true,
}}
to={generatePath(UPDATE_TAX_ROUTE, { id })}
to={generatePath(UPDATE_TAX_ROUTE, { taxId })}
>
{translate('text_645bb193927b375079d28b7c')}
</ButtonLink>
Expand Down
2 changes: 1 addition & 1 deletion src/core/router/ObjectsRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const CREATE_ADD_ON_ROUTE = '/create/add-on'
export const UPDATE_ADD_ON_ROUTE = '/update/add-on/:addOnId'

export const CREATE_TAX_ROUTE = '/create/tax'
export const UPDATE_TAX_ROUTE = '/update/tax/:id'
export const UPDATE_TAX_ROUTE = '/update/tax/:taxId'

export const CREATE_INVOICE_ROUTE = '/customer/:id/create-invoice'

Expand Down
14 changes: 7 additions & 7 deletions src/hooks/useCreateEditTax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ const formatTaxInput = (values: TaxFormInput) => {

export const useCreateEditTax: () => useCreateEditTaxReturn = () => {
const navigate = useNavigate()
const { id } = useParams()
const { taxId } = useParams()
const { data, loading, error } = useGetSingleTaxQuery({
context: { silentError: LagoApiError.NotFound },
variables: { id: id as string },
skip: !id,
variables: { id: taxId as string },
skip: !taxId,
})
const [update, { error: createError }] = useUpdateTaxMutation({
context: { silentErrorCodes: [LagoApiError.UnprocessableEntity] },
Expand Down Expand Up @@ -118,17 +118,17 @@ export const useCreateEditTax: () => useCreateEditTaxReturn = () => {
() => ({
loading,
errorCode,
isEdition: !!id,
isEdition: !!taxId,
tax: data?.tax || undefined,
onClose: () => {
navigate(TAXES_SETTINGS_ROUTE)
},
onSave: !!id
onSave: !!taxId
? async (values) => {
await update({
variables: {
input: {
id,
id: taxId,
...formatTaxInput(values),
},
},
Expand All @@ -142,6 +142,6 @@ export const useCreateEditTax: () => useCreateEditTaxReturn = () => {
})
},
}),
[id, create, data, errorCode, loading, navigate, update]
[loading, errorCode, taxId, data?.tax, navigate, update, create]
)
}

0 comments on commit 93d04d3

Please sign in to comment.