Skip to content

Commit 0430b18

Browse files
epmkellyshaunmaharaj
authored andcommitted
[PB-5819] Buyer Admins should not see data that only Seller Admins should see (#452)
There were some changes to the apis for the Admin dashboard, this pr makes it so that only Seller Admins see external-id.
1 parent abbce68 commit 0430b18

File tree

5 files changed

+85
-28
lines changed

5 files changed

+85
-28
lines changed

app/src/containers/b2b/AccountMain.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ import * as Config from '../../ep.config.json';
3434
import './AccountMain.less';
3535

3636
const accountZoomArray = [
37+
'accountmetadata',
3738
'selfsignupinfo',
3839
'statusinfo',
3940
'statusinfo:status',
4041
'subaccounts',
4142
'subaccounts:element',
43+
'subaccounts:element:accountmetadata',
4244
'subaccounts:element:subaccounts',
4345
'subaccounts:element:subaccounts:element',
4446
'subaccounts:element:statusinfo',
@@ -108,7 +110,9 @@ interface AccountMainState {
108110
isAddAssociateOpen: boolean,
109111
addAssociateUri: string,
110112
addSubAccountUri: string,
113+
addSubAccountSellerAdmin: boolean,
111114
editSubAccountUri: string,
115+
editMetadataUri: string,
112116
subAccounts: any,
113117
}
114118

@@ -139,7 +143,9 @@ export default class AccountMain extends React.Component<RouteComponentProps<Acc
139143
associateEditEmail: '',
140144
addAssociateUri: '',
141145
addSubAccountUri: '',
146+
addSubAccountSellerAdmin: false,
142147
editSubAccountUri: '',
148+
editMetadataUri: '',
143149
subAccounts: {},
144150
};
145151

@@ -186,17 +192,19 @@ export default class AccountMain extends React.Component<RouteComponentProps<Acc
186192
this.setState({
187193
accountName: accounts.name,
188194
mainAccountName: accounts.name,
189-
externalId: accounts['external-id'],
195+
externalId: accounts._accountmetadata ? accounts._accountmetadata[0]['external-id'] : null,
190196
registrationNumber: accounts['registration-id'],
191197
isLoading: false,
192198
legalName: accounts['legal-name'],
193199
associates: accounts._associateroleassignments[0]._element ? accounts._associateroleassignments[0]._element.map(element => ({ associate: element._associate[0], roles: element._roleinfo[0] })) : [],
194200
status: accounts._statusinfo[0]._status[0].status,
195201
editSubAccountUri: accounts.self.uri,
202+
editMetadataUri: accounts._accountmetadata ? accounts._accountmetadata[0].self.uri : null,
196203
selfSignUpCode: accounts._selfsignupinfo ? accounts._selfsignupinfo[0]['self-signup-code'] : '',
197204
userEmail: profile._myprofile[0]._primaryemail[0].email,
198205
addAssociateUri: accounts._associateroleassignments[0]._associateform[0]._addassociateaction[0].self.uri,
199206
addSubAccountUri: accounts._subaccounts[0]._accountform[0].self.uri,
207+
addSubAccountSellerAdmin: typeof accounts._subaccounts[0]._accountform[0]['external-id'] !== 'undefined',
200208
subAccounts: accounts._subaccounts[0],
201209
});
202210
})
@@ -212,13 +220,15 @@ export default class AccountMain extends React.Component<RouteComponentProps<Acc
212220
subAccountData(data) {
213221
this.setState({
214222
accountName: data.name,
215-
externalId: data['external-id'],
223+
externalId: data._accountmetadata ? data._accountmetadata[0]['external-id'] : null,
216224
registrationNumber: data['registration-id'],
217225
legalName: data['legal-name'],
218226
associates: data._associateroleassignments[0]._element ? data._associateroleassignments[0]._element.map(element => ({ associate: element._associate[0], roles: element._roleinfo[0] })) : [],
219227
addAssociateUri: data._associateroleassignments[0]._associateform[0]._addassociateaction[0].self.uri,
220228
addSubAccountUri: data._subaccounts[0]._accountform[0].self.uri,
229+
addSubAccountSellerAdmin: typeof data._subaccounts[0]._accountform[0]['external-id'] !== 'undefined',
221230
editSubAccountUri: data.self.uri,
231+
editMetadataUri: data._accountmetadata ? data._accountmetadata[0].self.uri : null,
222232
});
223233
}
224234

@@ -270,7 +280,9 @@ export default class AccountMain extends React.Component<RouteComponentProps<Acc
270280
userEmail,
271281
addAssociateUri,
272282
addSubAccountUri,
283+
addSubAccountSellerAdmin,
273284
editSubAccountUri,
285+
editMetadataUri,
274286
isAddAssociateOpen,
275287
subAccounts,
276288
mainAccountName,
@@ -386,6 +398,7 @@ export default class AccountMain extends React.Component<RouteComponentProps<Acc
386398
isOpen={isSettingsDialogOpen}
387399
accountData={editAccountData}
388400
editSubAccountUri={editSubAccountUri}
401+
editMetadataUri={editMetadataUri}
389402
/>
390403
<EditAssociate
391404
handleClose={this.isEditAssociateClose}
@@ -404,6 +417,7 @@ export default class AccountMain extends React.Component<RouteComponentProps<Acc
404417
handleUpdate={this.handleAccountSettingsUpdate}
405418
isOpen={isAddSubAccountOpen}
406419
addSubAccountUri={addSubAccountUri}
420+
addSubAccountSellerAdmin={addSubAccountSellerAdmin}
407421
/>
408422
</div>
409423
</div>

app/src/containers/b2b/AddSubAccount.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ interface AddSubAccountProps {
3434
handleClose: () => void,
3535
handleUpdate: () => void,
3636
addSubAccountUri: string,
37+
addSubAccountSellerAdmin: boolean,
3738
}
3839

3940
interface AddSubAccountState {
@@ -101,11 +102,12 @@ export default class AddSubAccount extends React.Component<AddSubAccountProps, A
101102
const { name } = event.target;
102103
const { value } = event.target;
103104

104-
this.setState({ name: value });
105+
// @ts-ignore
106+
this.setState({ [name]: value });
105107
}
106108

107109
render() {
108-
const { isOpen, handleClose } = this.props;
110+
const { isOpen, handleClose, addSubAccountSellerAdmin } = this.props;
109111
const {
110112
name, legalName, externalId, registrationNumber, isLoading,
111113
} = this.state;
@@ -130,14 +132,16 @@ export default class AddSubAccount extends React.Component<AddSubAccountProps, A
130132
</label>
131133
</div>
132134
<div className="b2b-form-row">
133-
<label htmlFor="external-id" className="b2b-form-col">
134-
<p className="b2b-dark-text">{intl.get('external-id')}</p>
135-
<input id="external-id" className="b2b-input" value={externalId || ''} onChange={this.changeHandler} name="externalId" type="text" />
136-
</label>
137135
<label htmlFor="registration-number" className="b2b-form-col">
138136
<p className="b2b-dark-text">{intl.get('registration-number')}</p>
139137
<input id="registration-number" className="b2b-input" value={registrationNumber || ''} onChange={this.changeHandler} name="registrationNumber" type="text" />
140138
</label>
139+
{addSubAccountSellerAdmin && (
140+
<label htmlFor="external-id" className="b2b-form-col">
141+
<p className="b2b-dark-text">{intl.get('external-id')}</p>
142+
<input id="external-id" className="b2b-input" value={externalId || ''} onChange={this.changeHandler} name="externalId" type="text" />
143+
</label>)
144+
}
141145
</div>
142146
</form>
143147
</div>

app/src/containers/b2b/Dashboard.tsx

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ interface DashboardState {
4040
isLoading: boolean,
4141
showSearchLoader: boolean,
4242
noSearchResults: boolean,
43+
isSellerAdmin: boolean,
4344
}
4445

4546
const accountsZoomArray = [
4647
'accounts',
4748
'accounts:element',
49+
'accounts:element:accountmetadata',
4850
'accounts:element:selfsignupinfo',
4951
'accounts:element:statusinfo',
5052
'accounts:element:statusinfo:status',
@@ -118,6 +120,7 @@ export default class Dashboard extends React.Component<RouteComponentProps, Dash
118120
accounts: [],
119121
admins: [],
120122
searchAccounts: '',
123+
isSellerAdmin: false,
121124
};
122125
this.getAdminData();
123126
this.setSearchAccounts = this.setSearchAccounts.bind(this);
@@ -144,11 +147,15 @@ export default class Dashboard extends React.Component<RouteComponentProps, Dash
144147
const uri = account.self.uri.split('/').pop();
145148
return {
146149
name: account.name,
147-
externalId: account['external-id'],
150+
externalId: account._accountmetadata ? account._accountmetadata[0]['external-id'] : null,
148151
status: account._statusinfo[0]._status[0].status.toLowerCase(),
149152
uri,
150153
};
151154
});
155+
let isSellerAdmin = false;
156+
if (res._accounts[0]._element[0]._accountmetadata) {
157+
isSellerAdmin = true;
158+
}
152159
const map = new Map();
153160
res._accounts[0]._element.reduce((accum, account) => {
154161
const associates = account._associateroleassignments[0]._element;
@@ -166,7 +173,7 @@ export default class Dashboard extends React.Component<RouteComponentProps, Dash
166173
const admins = Array.from(map.values());
167174

168175
this.setState({
169-
accounts, admins, isLoading: false, noSearchResults: false,
176+
accounts, admins, isLoading: false, noSearchResults: false, isSellerAdmin,
170177
});
171178
}
172179
});
@@ -209,12 +216,21 @@ export default class Dashboard extends React.Component<RouteComponentProps, Dash
209216
const uri = account.self.uri.split('/').pop();
210217
return {
211218
name: account.name,
212-
externalId: account['external-id'],
219+
externalId: account._accountmetadata[0]['external-id'],
213220
status: account._statusinfo[0]._status[0].status.toLowerCase(),
214221
uri,
215222
};
216223
});
217-
this.setState({ accounts, showSearchLoader: false, noSearchResults: false });
224+
let isSellerAdmin = false;
225+
if (res._accounts[0]._element[0]._accountmetadata) {
226+
isSellerAdmin = true;
227+
}
228+
this.setState({
229+
accounts,
230+
showSearchLoader: false,
231+
noSearchResults: false,
232+
isSellerAdmin,
233+
});
218234
} else {
219235
this.setState({ showSearchLoader: false, noSearchResults: true });
220236
}
@@ -258,6 +274,7 @@ export default class Dashboard extends React.Component<RouteComponentProps, Dash
258274
searchAccounts,
259275
showSearchLoader,
260276
noSearchResults,
277+
isSellerAdmin,
261278
} = this.state;
262279

263280
return (
@@ -387,14 +404,16 @@ export default class Dashboard extends React.Component<RouteComponentProps, Dash
387404
<tr>
388405
<th className="name">
389406
{intl.get('name')}
390-
<span className="mobile-table-title">
391-
{' '}
392-
&
393-
{' '}
394-
{intl.get('external-id')}
395-
</span>
407+
{isSellerAdmin && (
408+
<span className="mobile-table-title">
409+
{' '}
410+
&
411+
{' '}
412+
{intl.get('external-id')}
413+
</span>)
414+
}
396415
</th>
397-
<th className="external-id">{intl.get('external-id')}</th>
416+
{isSellerAdmin && <th className="external-id">{intl.get('external-id')}</th>}
398417
<th className="status">{intl.get('status')}</th>
399418
<th className="arrow" />
400419
</tr>
@@ -403,7 +422,7 @@ export default class Dashboard extends React.Component<RouteComponentProps, Dash
403422
{accounts.map(account => (
404423
<tr key={account.uri} onClick={() => this.handleAccountClicked(account)} className="account-list-rows">
405424
<td className="name">{account.name}</td>
406-
<td className="external-id">{account.externalId}</td>
425+
{isSellerAdmin && <td className="external-id">{account.externalId}</td>}
407426
<td className="status">
408427
<i className={`icons-status ${account.status.toLowerCase()}`} />
409428
{intl.get(account.status)}

app/src/containers/b2b/EditAccount.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
width: 100%;
4747
padding: 0;
4848
}
49-
&:last-child {
49+
&:last-child:not(:only-child) {
5050
padding-right: 0;
5151
padding-left: 20px;
5252

app/src/containers/b2b/EditAccount.tsx

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const COPIED_TIMEOUT_LENGTH = 4000;
3636
interface EditAccountProps {
3737
isOpen: boolean,
3838
editSubAccountUri: string,
39+
editMetadataUri: string,
3940
handleClose: () => void,
4041
handleUpdate: () => void,
4142
accountData: {
@@ -95,7 +96,9 @@ export default class EditAccount extends React.Component<EditAccountProps, EditA
9596
}
9697

9798
editAccount(event) {
98-
const { handleClose, handleUpdate, editSubAccountUri } = this.props;
99+
const {
100+
handleClose, handleUpdate, editSubAccountUri, editMetadataUri,
101+
} = this.props;
99102
const {
100103
name, legalName, externalId, registrationNumber,
101104
} = this.state;
@@ -111,11 +114,24 @@ export default class EditAccount extends React.Component<EditAccountProps, EditA
111114
},
112115
body: JSON.stringify({
113116
name,
114-
'external-id': externalId,
115117
'legal-name': legalName,
116118
'registration-id': registrationNumber,
117119
}),
118120
})
121+
.then(() => {
122+
if (editMetadataUri) {
123+
adminFetch(`${editMetadataUri}`, {
124+
method: 'put',
125+
headers: {
126+
'Content-Type': 'application/json',
127+
Authorization: localStorage.getItem(`${Config.cortexApi.scope}_oAuthTokenAuthService`),
128+
},
129+
body: JSON.stringify({
130+
'external-id': externalId,
131+
}),
132+
});
133+
}
134+
})
119135
.then(() => {
120136
handleClose();
121137
handleUpdate();
@@ -147,7 +163,9 @@ export default class EditAccount extends React.Component<EditAccountProps, EditA
147163
}
148164

149165
render() {
150-
const { isOpen, handleClose, accountData } = this.props;
166+
const {
167+
isOpen, handleClose, accountData, editMetadataUri,
168+
} = this.props;
151169
const {
152170
name, legalName, externalId, registrationNumber, isShowingCopied, isLoading,
153171
} = this.state;
@@ -172,14 +190,16 @@ export default class EditAccount extends React.Component<EditAccountProps, EditA
172190
</label>
173191
</div>
174192
<div className="b2b-form-row">
175-
<label htmlFor="external-id" className="b2b-form-col">
176-
<p className="b2b-dark-text">{intl.get('external-id')}</p>
177-
<input id="external-id" className="b2b-input" value={externalId || ''} onChange={this.changeHandler} name="externalId" type="text" />
178-
</label>
179193
<label htmlFor="registration-number" className="b2b-form-col">
180194
<p className="b2b-dark-text">{intl.get('registration-number')}</p>
181195
<input id="registration-number" className="b2b-input" value={registrationNumber || ''} onChange={this.changeHandler} name="registrationNumber" type="text" />
182196
</label>
197+
{editMetadataUri && (
198+
<label htmlFor="external-id" className="b2b-form-col">
199+
<p className="b2b-dark-text">{intl.get('external-id')}</p>
200+
<input id="external-id" className="b2b-input" value={externalId || ''} onChange={this.changeHandler} name="externalId" type="text" />
201+
</label>)
202+
}
183203
</div>
184204
{accountData.selfSignUpCode && (
185205
<div className="b2b-form-row">

0 commit comments

Comments
 (0)