@@ -5,19 +5,13 @@ import { useQuery, useMutation } from 'react-apollo'
55import { PageBlock , Table , IconCheck , Button , Checkbox } from 'vtex.styleguide'
66import { useToast } from '@vtex/admin-ui'
77
8- import {
9- organizationSettingsMessages as messages ,
10- organizationMessages ,
11- } from './utils/messages'
8+ import { organizationSettingsMessages as messages } from './utils/messages'
129import { organizationBulkAction } from './utils/organizationBulkAction'
1310import GET_SALES_CHANNELS from '../graphql/getSalesChannels.graphql'
1411import SELECTED_SALES_CHANNELS from '../graphql/getSelectedChannels.graphql'
1512import UPDATE_SALES_CHANNELS from '../graphql/updateSalesChannels.graphql'
1613import UPDATE_B2B_SETTINGS from '../graphql/updateB2BSettings.graphql'
1714import GET_B2B_SETTINGS from '../graphql/getB2BSettings.graphql'
18- import GET_PAYMENT_TERMS from '../graphql/getPaymentTerms.graphql'
19- import type { PaymentTerm } from './OrganizationDetails/OrganizationDetailsPayTerms'
20- import GET_PRICE_TABLES from '../graphql/getPriceTables.graphql'
2115
2216interface SalesChannel {
2317 channelId : string
@@ -49,8 +43,6 @@ const OrganizationSettings: FunctionComponent = () => {
4943 autoApprove : false ,
5044 businessReadOnly : false ,
5145 stateReadOnly : false ,
52- defaultPaymentTerms : [ ] as any ,
53- defaultPriceTables : [ ] as any ,
5446 uiSettings : {
5547 clearCart : false ,
5648 showModal : false ,
@@ -66,12 +58,6 @@ const OrganizationSettings: FunctionComponent = () => {
6658 ssr : false ,
6759 } )
6860
69- const { data : paymentTermsData } = useQuery < {
70- getPaymentTerms : PaymentTerm [ ]
71- } > ( GET_PAYMENT_TERMS , { ssr : false } )
72-
73- const { data : priceTablesData } = useQuery ( GET_PRICE_TABLES , { ssr : false } )
74-
7561 const { data : dataSettings , refetch : refetchSettings } = useQuery (
7662 GET_B2B_SETTINGS ,
7763 {
@@ -83,35 +69,35 @@ const OrganizationSettings: FunctionComponent = () => {
8369 const [ updateB2BSettings ] = useMutation ( UPDATE_B2B_SETTINGS )
8470
8571 useEffect ( ( ) => {
86- if ( data ) {
87- const options : any [ ] = [ ]
72+ if ( ! data ) return
8873
89- data . salesChannels . forEach ( ( item : { id : string ; name : string } ) => {
90- options . push ( {
91- channelId : item . id ,
92- name : item . name ,
93- tableName : `${ item . name } (${ item . id } )` ,
94- } )
74+ const options : SalesChannel [ ] = [ ]
75+
76+ data . salesChannels . forEach ( ( item : { id : string ; name : string } ) => {
77+ options . push ( {
78+ channelId : item . id ,
79+ name : item . name ,
80+ tableName : `${ item . name } (${ item . id } )` ,
9581 } )
96- setSalesChannels ( options )
97- }
82+ } )
83+ setSalesChannels ( options )
9884 } , [ data ] )
9985
10086 useEffect ( ( ) => {
101- if ( selectedData ) {
102- const selectedOptions : any [ ] = [ ]
103-
104- selectedData . getSalesChannels . forEach (
105- ( item : { id : string ; name : string } ) => {
106- selectedOptions . push ( {
107- channelId : item . id ,
108- name : item . name ,
109- tableName : ` ${ item . name } ( ${ item . id } )` ,
110- } )
111- }
112- )
113- setSelectedChannel ( selectedOptions )
114- }
87+ if ( ! selectedData ) return
88+
89+ const selectedOptions : any [ ] = [ ]
90+
91+ selectedData . getSalesChannels . forEach (
92+ ( item : { id : string ; name : string } ) => {
93+ selectedOptions . push ( {
94+ channelId : item . id ,
95+ name : item . name ,
96+ tableName : ` ${ item . name } ( ${ item . id } )` ,
97+ } )
98+ }
99+ )
100+ setSelectedChannel ( selectedOptions )
115101 } , [ selectedData ] )
116102
117103 useEffect ( ( ) => {
@@ -125,8 +111,6 @@ const OrganizationSettings: FunctionComponent = () => {
125111 autoApprove : getB2BSettings ?. autoApprove ,
126112 businessReadOnly : getB2BSettings ?. businessReadOnly ,
127113 stateReadOnly : getB2BSettings ?. stateReadOnly ,
128- defaultPaymentTerms : getB2BSettings ?. defaultPaymentTerms ?? [ ] ,
129- defaultPriceTables : getB2BSettings ?. defaultPriceTables ?? [ ] ,
130114 uiSettings : {
131115 clearCart : getB2BSettings ?. uiSettings ?. clearCart ,
132116 showModal : getB2BSettings ?. uiSettings ?. showModal ,
@@ -355,74 +339,6 @@ const OrganizationSettings: FunctionComponent = () => {
355339 label = { formatMessage ( messages . fullImpersonation ) }
356340 />
357341 </ div >
358- < div className = "flex br3 pa6 b--muted-4 ba" >
359- < div className = "mb4 w-50" >
360- < h2 className = "mb4" >
361- { formatMessage ( organizationMessages . paymentTerms ) }
362- </ h2 >
363- { paymentTermsData ?. getPaymentTerms
364- . sort ( ( a : PaymentTerm , b : PaymentTerm ) => {
365- return a . name > b . name ? 1 : - 1
366- } )
367- . map ( ( payment : PaymentTerm ) => (
368- < div className = "mb4" >
369- < Checkbox
370- name = { payment . name }
371- id = { payment . name }
372- label = { payment . name }
373- checked = { settings ?. defaultPaymentTerms ?. some (
374- ( item : PaymentTerm ) => item . id === payment . id
375- ) }
376- onChange = { ( ) => {
377- const defaultPaymentTerms = settings . defaultPaymentTerms ?. some (
378- ( item : PaymentTerm ) => item . id === payment . id
379- )
380- ? settings . defaultPaymentTerms ?. filter (
381- ( item : PaymentTerm ) => item . id !== payment . id
382- )
383- : [ ...settings . defaultPaymentTerms , payment ]
384-
385- setSettings ( {
386- ...settings ,
387- defaultPaymentTerms,
388- } )
389- } }
390- />
391- </ div >
392- ) ) }
393- </ div >
394- < div className = "mb4 w-50" >
395- < h2 className = "mb4" >
396- { formatMessage ( organizationMessages . priceTables ) }
397- </ h2 >
398- { priceTablesData ?. priceTables . map ( ( priceTable : string ) => (
399- < div className = "mb4" >
400- < Checkbox
401- name = { priceTable }
402- id = { priceTable }
403- label = { priceTable }
404- checked = { settings ?. defaultPriceTables ?. some (
405- ( item : string ) => item === priceTable
406- ) }
407- onChange = { ( ) => {
408- const defaultPriceTables = settings . defaultPriceTables ?. some (
409- ( item : string ) => item === priceTable
410- )
411- ? settings . defaultPriceTables ?. filter (
412- ( item : string ) => item !== priceTable
413- )
414- : [ ...settings . defaultPriceTables , priceTable ]
415-
416- setSettings ( {
417- ...settings ,
418- defaultPriceTables,
419- } )
420- } }
421- />
422- </ div >
423- ) ) }
424- </ div >
425- </ div >
426342 </ div >
427343 </ div >
428344 < div className = "w-100 mt4 mb4" >
0 commit comments