Skip to content

Commit

Permalink
misc(netsuite) rename attributes for more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
ansmonjol committed May 3, 2024
1 parent 533245e commit b7fdff1
Show file tree
Hide file tree
Showing 6 changed files with 384 additions and 369 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import styled from 'styled-components'
import { Button, Popper, Typography } from '~/components/designSystem'
import { SearchInput } from '~/components/SearchInput'
import {
MappableTypeEnum,
NetsuiteIntegrationItemsListAddonsFragmentDoc,
NetsuiteIntegrationItemsListBillableMetricsFragmentDoc,
NetsuiteIntegrationItemsListDefaultFragmentDoc,
NetsuiteMappableTypeEnum,
useGetAddOnsForNetsuiteItemsListLazyQuery,
useGetBillableMetricsForNetsuiteItemsListLazyQuery,
useGetNetsuiteCollectionMappingsLazyQuery,
useGetIntegrationCollectionMappingsLazyQuery,
} from '~/generated/graphql'
import { useInternationalization } from '~/hooks/core/useInternationalization'
import { useDebouncedSearch } from '~/hooks/useDebouncedSearch'
Expand All @@ -26,23 +26,23 @@ import { NetsuiteMapItemDialog, NetsuiteMapItemDialogRef } from './NetsuiteMapIt

const SelectedItemTypeEnum = {
Default: 'Default',
[NetsuiteMappableTypeEnum.AddOn]: 'AddOn',
[NetsuiteMappableTypeEnum.BillableMetric]: 'BillableMetric',
[MappableTypeEnum.AddOn]: 'AddOn',
[MappableTypeEnum.BillableMetric]: 'BillableMetric',
} as const

const SelectedItemTypeEnumTranslation = {
Default: 'text_65281f686a80b400c8e2f6d1',
[NetsuiteMappableTypeEnum.AddOn]: 'text_629728388c4d2300e2d3801a',
[NetsuiteMappableTypeEnum.BillableMetric]: 'text_623b497ad05b960101be3438',
[MappableTypeEnum.AddOn]: 'text_629728388c4d2300e2d3801a',
[MappableTypeEnum.BillableMetric]: 'text_623b497ad05b960101be3438',
} as const

gql`
fragment NetsuiteIntegrationItems on NetsuiteIntegration {
id # integrationId received in props
}
query getNetsuiteCollectionMappings($integrationId: ID!) {
netsuiteCollectionMappings(integrationId: $integrationId) {
query getIntegrationCollectionMappings($integrationId: ID!) {
integrationCollectionMappings(integrationId: $integrationId) {
collection {
id
...NetsuiteIntegrationItemsListDefault
Expand Down Expand Up @@ -101,7 +101,7 @@ const NetsuiteIntegrationItemsList = ({ integrationId }: { integrationId: string
loading: collectionMappingLoading,
error: collectionMappingError,
},
] = useGetNetsuiteCollectionMappingsLazyQuery({
] = useGetIntegrationCollectionMappingsLazyQuery({
notifyOnNetworkStatusChange: true,
variables: {
integrationId,
Expand Down Expand Up @@ -150,9 +150,9 @@ const NetsuiteIntegrationItemsList = ({ integrationId }: { integrationId: string
useEffect(() => {
if (selectedItemType === SelectedItemTypeEnum.Default) {
getDefaultItems()
} else if (selectedItemType === NetsuiteMappableTypeEnum.AddOn) {
} else if (selectedItemType === MappableTypeEnum.AddOn) {
getAddonList()
} else if (selectedItemType === NetsuiteMappableTypeEnum.BillableMetric) {
} else if (selectedItemType === MappableTypeEnum.BillableMetric) {
getBillableMetricsList()
}
}, [selectedItemType, getAddonList, getDefaultItems, getBillableMetricsList])
Expand Down Expand Up @@ -190,7 +190,7 @@ const NetsuiteIntegrationItemsList = ({ integrationId }: { integrationId: string
align="left"
fullWidth
onClick={() => {
setSelectedItemType(NetsuiteMappableTypeEnum.AddOn)
setSelectedItemType(MappableTypeEnum.AddOn)
closePopper()
}}
>
Expand All @@ -201,7 +201,7 @@ const NetsuiteIntegrationItemsList = ({ integrationId }: { integrationId: string
align="left"
fullWidth
onClick={() => {
setSelectedItemType(NetsuiteMappableTypeEnum.BillableMetric)
setSelectedItemType(MappableTypeEnum.BillableMetric)
closePopper()
}}
>
Expand All @@ -212,12 +212,12 @@ const NetsuiteIntegrationItemsList = ({ integrationId }: { integrationId: string
</Popper>
</Stack>

{selectedItemType === NetsuiteMappableTypeEnum.AddOn ? (
{selectedItemType === MappableTypeEnum.AddOn ? (
<SearchInput
onChange={debouncedSearchAddons}
placeholder={translate('text_63bee4e10e2d53912bfe4db8')}
/>
) : selectedItemType === NetsuiteMappableTypeEnum.BillableMetric ? (
) : selectedItemType === MappableTypeEnum.BillableMetric ? (
<SearchInput
onChange={debouncedSearchBillableMetrics}
placeholder={translate('text_63ba9ee977a67c9693f50aea')}
Expand All @@ -227,13 +227,13 @@ const NetsuiteIntegrationItemsList = ({ integrationId }: { integrationId: string

{selectedItemType === SelectedItemTypeEnum.Default ? (
<NetsuiteIntegrationItemsListDefault
defaultItems={collectionMappingData?.netsuiteCollectionMappings?.collection}
defaultItems={collectionMappingData?.integrationCollectionMappings?.collection}
integrationId={integrationId}
isLoading={collectionMappingLoading}
hasError={!!collectionMappingError}
netsuiteMapItemDialogRef={netsuiteMapItemDialogRef}
/>
) : selectedItemType === NetsuiteMappableTypeEnum.AddOn ? (
) : selectedItemType === MappableTypeEnum.AddOn ? (
<NetsuiteIntegrationItemsListAddons
data={addonData}
fetchMoreAddons={fetchMoreAddons}
Expand All @@ -243,7 +243,7 @@ const NetsuiteIntegrationItemsList = ({ integrationId }: { integrationId: string
netsuiteMapItemDialogRef={netsuiteMapItemDialogRef}
searchTerm={addonVariables?.searchTerm}
/>
) : selectedItemType === NetsuiteMappableTypeEnum.BillableMetric ? (
) : selectedItemType === MappableTypeEnum.BillableMetric ? (
<NetsuiteIntegrationItemsListBillableMetrics
data={billableMetricsData}
fetchMoreBillableMetrics={fetchMoreBillableMetrics}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { CREATE_ADD_ON_ROUTE } from '~/core/router'
import {
GetAddOnsForNetsuiteItemsListQuery,
InputMaybe,
NetsuiteMappableTypeEnum,
MappableTypeEnum,
} from '~/generated/graphql'
import { useInternationalization } from '~/hooks/core/useInternationalization'
import EmptyImage from '~/public/images/maneki/empty.svg'
Expand All @@ -24,11 +24,12 @@ gql`
id
name
code
netsuiteMapping {
integrationMappings {
id
externalId
externalAccountCode
externalName
mappableType
}
}
`
Expand Down Expand Up @@ -124,6 +125,10 @@ const NetsuiteIntegrationItemsListAddons = ({
<>
{!!addons.length &&
addons.map((addOn) => {
const addonMapping = addOn?.integrationMappings?.find(
(i) => i.mappableType === MappableTypeEnum.AddOn,
)

return (
<NetsuiteIntegrationItemLine
key={`addon-item-${addOn.id}`}
Expand All @@ -134,16 +139,16 @@ const NetsuiteIntegrationItemsListAddons = ({
onMappingClick={() => {
netsuiteMapItemDialogRef.current?.openDialog({
integrationId,
type: NetsuiteMappableTypeEnum.AddOn,
itemId: addOn?.netsuiteMapping?.id,
itemExternalId: addOn?.netsuiteMapping?.externalId,
itemExternalCode: addOn?.netsuiteMapping?.externalAccountCode || undefined,
itemExternalName: addOn?.netsuiteMapping?.externalName || undefined,
type: MappableTypeEnum.AddOn,
itemId: addonMapping?.id,
itemExternalId: addonMapping?.externalId,
itemExternalCode: addonMapping?.externalAccountCode || undefined,
itemExternalName: addonMapping?.externalName || undefined,
lagoMappableId: addOn.id,
})
}}
mappingInfos={
!!addOn?.netsuiteMapping?.id
!!addonMapping?.id
? {
id: addonMapping.externalId,
name: addonMapping.externalName || '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { CREATE_BILLABLE_METRIC_ROUTE } from '~/core/router'
import {
GetBillableMetricsForNetsuiteItemsListQuery,
InputMaybe,
NetsuiteMappableTypeEnum,
MappableTypeEnum,
} from '~/generated/graphql'
import { useInternationalization } from '~/hooks/core/useInternationalization'
import EmptyImage from '~/public/images/maneki/empty.svg'
Expand All @@ -24,11 +24,12 @@ gql`
id
name
code
netsuiteMapping {
integrationMappings {
id
externalId
externalAccountCode
externalName
mappableType
}
}
`
Expand Down Expand Up @@ -124,6 +125,10 @@ const NetsuiteIntegrationItemsListBillableMetrics = ({
<>
{!!billableMetrics.length &&
billableMetrics.map((billableMetric) => {
const billableMetricMapping = billableMetric.integrationMappings?.find(
(mapping) => mapping.mappableType === MappableTypeEnum.BillableMetric,
)

return (
<NetsuiteIntegrationItemLine
key={`billableMetric-item-${billableMetric.id}`}
Expand All @@ -134,18 +139,16 @@ const NetsuiteIntegrationItemsListBillableMetrics = ({
onMappingClick={() => {
netsuiteMapItemDialogRef.current?.openDialog({
integrationId,
type: NetsuiteMappableTypeEnum.BillableMetric,
itemId: billableMetric?.netsuiteMapping?.id,
itemExternalId: billableMetric?.netsuiteMapping?.externalId,
itemExternalCode:
billableMetric?.netsuiteMapping?.externalAccountCode || undefined,
itemExternalName:
billableMetric?.netsuiteMapping?.externalName || undefined,
type: MappableTypeEnum.BillableMetric,
itemId: billableMetricMapping?.id,
itemExternalId: billableMetricMapping?.externalId,
itemExternalCode: billableMetricMapping?.externalAccountCode || undefined,
itemExternalName: billableMetricMapping?.externalName || undefined,
lagoMappableId: billableMetric.id,
})
}}
mappingInfos={
!!billableMetric?.netsuiteMapping?.id
!!billableMetricMapping?.id
? {
id: billableMetricMapping.externalId,
name: billableMetricMapping.externalName || '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { Stack } from '@mui/material'
import { RefObject, useMemo } from 'react'

import { GenericPlaceholder } from '~/components/GenericPlaceholder'
import {
NetsuiteIntegrationItemsListDefaultFragment,
NetsuiteMappingTypeEnum,
} from '~/generated/graphql'
import { MappingTypeEnum, NetsuiteIntegrationItemsListDefaultFragment } from '~/generated/graphql'
import { useInternationalization } from '~/hooks/core/useInternationalization'
import ErrorImage from '~/public/images/maneki/error.svg'

Expand All @@ -15,7 +12,7 @@ import NetsuiteIntegrationItemLine from './NetsuiteIntegrationItemLine'
import { NetsuiteMapItemDialogRef } from './NetsuiteMapItemDialog'

gql`
fragment NetsuiteIntegrationItemsListDefault on NetsuiteCollectionMapping {
fragment NetsuiteIntegrationItemsListDefault on CollectionMapping {
id
mappingType
externalId
Expand Down Expand Up @@ -45,21 +42,19 @@ const NetsuiteIntegrationItemsListDefault = ({
useMemo(() => {
return {
fallbackItem: defaultItems?.find(
(mapping) => mapping.mappingType === NetsuiteMappingTypeEnum.FallbackItem,
),
coupon: defaultItems?.find(
(mapping) => mapping.mappingType === NetsuiteMappingTypeEnum.Coupon,
(mapping) => mapping.mappingType === MappingTypeEnum.FallbackItem,
),
coupon: defaultItems?.find((mapping) => mapping.mappingType === MappingTypeEnum.Coupon),
minimumCommitment: defaultItems?.find(
(mapping) => mapping.mappingType === NetsuiteMappingTypeEnum.MinimumCommitment,
(mapping) => mapping.mappingType === MappingTypeEnum.MinimumCommitment,
),
prepaidCredit: defaultItems?.find(
(mapping) => mapping.mappingType === NetsuiteMappingTypeEnum.PrepaidCredit,
(mapping) => mapping.mappingType === MappingTypeEnum.PrepaidCredit,
),
subscriptionFee: defaultItems?.find(
(mapping) => mapping.mappingType === NetsuiteMappingTypeEnum.SubscriptionFee,
(mapping) => mapping.mappingType === MappingTypeEnum.SubscriptionFee,
),
tax: defaultItems?.find((mapping) => mapping.mappingType === NetsuiteMappingTypeEnum.Tax),
tax: defaultItems?.find((mapping) => mapping.mappingType === MappingTypeEnum.Tax),
}
}, [defaultItems])

Expand Down Expand Up @@ -87,7 +82,7 @@ const NetsuiteIntegrationItemsListDefault = ({
onMappingClick={() => {
netsuiteMapItemDialogRef.current?.openDialog({
integrationId,
type: NetsuiteMappingTypeEnum.FallbackItem,
type: MappingTypeEnum.FallbackItem,
itemId: fallbackItem?.id,
itemExternalId: fallbackItem?.externalId,
itemExternalCode: fallbackItem?.externalAccountCode || undefined,
Expand All @@ -112,7 +107,7 @@ const NetsuiteIntegrationItemsListDefault = ({
onMappingClick={() => {
netsuiteMapItemDialogRef.current?.openDialog({
integrationId,
type: NetsuiteMappingTypeEnum.Coupon,
type: MappingTypeEnum.Coupon,
itemId: coupon?.id,
itemExternalId: coupon?.externalId,
itemExternalCode: coupon?.externalAccountCode || undefined,
Expand All @@ -137,7 +132,7 @@ const NetsuiteIntegrationItemsListDefault = ({
onMappingClick={() => {
netsuiteMapItemDialogRef.current?.openDialog({
integrationId,
type: NetsuiteMappingTypeEnum.SubscriptionFee,
type: MappingTypeEnum.SubscriptionFee,
itemId: subscriptionFee?.id,
itemExternalId: subscriptionFee?.externalId,
itemExternalCode: subscriptionFee?.externalAccountCode || undefined,
Expand All @@ -161,7 +156,7 @@ const NetsuiteIntegrationItemsListDefault = ({
onMappingClick={() => {
netsuiteMapItemDialogRef.current?.openDialog({
integrationId,
type: NetsuiteMappingTypeEnum.MinimumCommitment,
type: MappingTypeEnum.MinimumCommitment,
itemId: minimumCommitment?.id,
itemExternalId: minimumCommitment?.externalId,
itemExternalCode: minimumCommitment?.externalAccountCode || undefined,
Expand All @@ -186,7 +181,7 @@ const NetsuiteIntegrationItemsListDefault = ({
onMappingClick={() => {
netsuiteMapItemDialogRef.current?.openDialog({
integrationId,
type: NetsuiteMappingTypeEnum.Tax,
type: MappingTypeEnum.Tax,
itemId: tax?.id,
itemExternalId: tax?.externalId,
itemExternalCode: tax?.externalAccountCode || undefined,
Expand All @@ -211,7 +206,7 @@ const NetsuiteIntegrationItemsListDefault = ({
onMappingClick={() => {
netsuiteMapItemDialogRef.current?.openDialog({
integrationId,
type: NetsuiteMappingTypeEnum.PrepaidCredit,
type: MappingTypeEnum.PrepaidCredit,
itemId: prepaidCredit?.id,
itemExternalId: prepaidCredit?.externalId,
itemExternalCode: prepaidCredit?.externalAccountCode || undefined,
Expand Down
Loading

0 comments on commit b7fdff1

Please sign in to comment.