Skip to content

Commit

Permalink
Merge pull request #185 from Josmar-jr/feat/remove-payment-terms-and-…
Browse files Browse the repository at this point in the history
…price-table

Feat/remove payment terms and price table
  • Loading branch information
ataideverton authored Jan 7, 2025
2 parents 2bf732d + 0fcdcb6 commit a1dd29e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 114 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Changed
- Remove payment terms and price table configuration

## [1.39.5] - 2024-12-12

## [1.39.4] - 2024-12-12
Expand Down
144 changes: 30 additions & 114 deletions react/admin/OrganizationSettings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@ import { useQuery, useMutation } from 'react-apollo'
import { PageBlock, Table, IconCheck, Button, Checkbox } from 'vtex.styleguide'
import { Spinner, useToast } from '@vtex/admin-ui'

import {
organizationSettingsMessages as messages,
organizationMessages,
} from '../utils/messages'
import { organizationSettingsMessages as messages } from '../utils/messages'
import { organizationBulkAction } from '../utils/organizationBulkAction'
import GET_SALES_CHANNELS from '../../graphql/getSalesChannels.graphql'
import SELECTED_SALES_CHANNELS from '../../graphql/getSelectedChannels.graphql'
import UPDATE_SALES_CHANNELS from '../../graphql/updateSalesChannels.graphql'
import UPDATE_B2B_SETTINGS from '../../graphql/updateB2BSettings.graphql'
import GET_B2B_SETTINGS from '../../graphql/getB2BSettings.graphql'
import GET_PAYMENT_TERMS from '../../graphql/getPaymentTerms.graphql'
import type { PaymentTerm } from '../OrganizationDetails/OrganizationDetailsPayTerms'
import GET_PRICE_TABLES from '../../graphql/getPriceTables.graphql'
import GET_SALES_CHANNELS from '../graphql/getSalesChannels.graphql'
import SELECTED_SALES_CHANNELS from '../graphql/getSelectedChannels.graphql'
import UPDATE_SALES_CHANNELS from '../graphql/updateSalesChannels.graphql'
import UPDATE_B2B_SETTINGS from '../graphql/updateB2BSettings.graphql'
import GET_B2B_SETTINGS from '../graphql/getB2BSettings.graphql'
import { TopbarCustom } from './TopbarCustom'

interface SalesChannel {
Expand Down Expand Up @@ -51,8 +45,6 @@ const OrganizationSettings: FunctionComponent = () => {
autoApprove: false,
businessReadOnly: false,
stateReadOnly: false,
defaultPaymentTerms: [] as any,
defaultPriceTables: [] as any,
uiSettings: {
clearCart: false,
showModal: false,
Expand All @@ -75,12 +67,6 @@ const OrganizationSettings: FunctionComponent = () => {
ssr: false,
})

const { data: paymentTermsData } = useQuery<{
getPaymentTerms: PaymentTerm[]
}>(GET_PAYMENT_TERMS, { ssr: false })

const { data: priceTablesData } = useQuery(GET_PRICE_TABLES, { ssr: false })

const {
data: dataSettings,
loading: loadingSettings,
Expand All @@ -93,35 +79,35 @@ const OrganizationSettings: FunctionComponent = () => {
const [updateB2BSettings] = useMutation(UPDATE_B2B_SETTINGS)

useEffect(() => {
if (data) {
const options: any[] = []
if (!data) return

data.salesChannels.forEach((item: { id: string; name: string }) => {
options.push({
channelId: item.id,
name: item.name,
tableName: `${item.name} (${item.id})`,
})
const options: SalesChannel[] = []

data.salesChannels.forEach((item: { id: string; name: string }) => {
options.push({
channelId: item.id,
name: item.name,
tableName: `${item.name} (${item.id})`,
})
setSalesChannels(options)
}
})
setSalesChannels(options)
}, [data])

useEffect(() => {
if (selectedData) {
const selectedOptions: any[] = []

selectedData.getSalesChannels.forEach(
(item: { id: string; name: string }) => {
selectedOptions.push({
channelId: item.id,
name: item.name,
tableName: `${item.name} (${item.id})`,
})
}
)
setSelectedChannel(selectedOptions)
}
if (!selectedData) return

const selectedOptions: any[] = []

selectedData.getSalesChannels.forEach(
(item: { id: string; name: string }) => {
selectedOptions.push({
channelId: item.id,
name: item.name,
tableName: `${item.name} (${item.id})`,
})
}
)
setSelectedChannel(selectedOptions)
}, [selectedData])

useEffect(() => {
Expand All @@ -135,8 +121,6 @@ const OrganizationSettings: FunctionComponent = () => {
autoApprove: getB2BSettings?.autoApprove,
businessReadOnly: getB2BSettings?.businessReadOnly,
stateReadOnly: getB2BSettings?.stateReadOnly,
defaultPaymentTerms: getB2BSettings?.defaultPaymentTerms ?? [],
defaultPriceTables: getB2BSettings?.defaultPriceTables ?? [],
uiSettings: {
clearCart: getB2BSettings?.uiSettings?.clearCart,
showModal: getB2BSettings?.uiSettings?.showModal,
Expand Down Expand Up @@ -411,74 +395,6 @@ const OrganizationSettings: FunctionComponent = () => {
label={formatMessage(messages.fullImpersonation)}
/>
</div>
<div className="flex br3 pa6 b--muted-4 ba">
<div className="mb4 w-50">
<h2 className="mb4">
{formatMessage(organizationMessages.paymentTerms)}
</h2>
{paymentTermsData?.getPaymentTerms
.sort((a: PaymentTerm, b: PaymentTerm) => {
return a.name > b.name ? 1 : -1
})
.map((payment: PaymentTerm) => (
<div className="mb4">
<Checkbox
name={payment.name}
id={payment.name}
label={payment.name}
checked={settings?.defaultPaymentTerms?.some(
(item: PaymentTerm) => item.id === payment.id
)}
onChange={() => {
const defaultPaymentTerms = settings.defaultPaymentTerms?.some(
(item: PaymentTerm) => item.id === payment.id
)
? settings.defaultPaymentTerms?.filter(
(item: PaymentTerm) => item.id !== payment.id
)
: [...settings.defaultPaymentTerms, payment]

setSettings({
...settings,
defaultPaymentTerms,
})
}}
/>
</div>
))}
</div>
<div className="mb4 w-50">
<h2 className="mb4">
{formatMessage(organizationMessages.priceTables)}
</h2>
{priceTablesData?.priceTables.map((priceTable: string) => (
<div className="mb4">
<Checkbox
name={priceTable}
id={priceTable}
label={priceTable}
checked={settings?.defaultPriceTables?.some(
(item: string) => item === priceTable
)}
onChange={() => {
const defaultPriceTables = settings.defaultPriceTables?.some(
(item: string) => item === priceTable
)
? settings.defaultPriceTables?.filter(
(item: string) => item !== priceTable
)
: [...settings.defaultPriceTables, priceTable]

setSettings({
...settings,
defaultPriceTables,
})
}}
/>
</div>
))}
</div>
</div>
</div>
</div>
<div className="w-100 mt4 mb4">
Expand Down

0 comments on commit a1dd29e

Please sign in to comment.