Skip to content

Commit 71cdd6c

Browse files
committed
feat(open-service): rename myaccount-settings to myaccount
1 parent 6f3b194 commit 71cdd6c

File tree

7 files changed

+171
-145
lines changed

7 files changed

+171
-145
lines changed

docs/README.md

+97-96
Large diffs are not rendered by default.

sample/src/elements.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export default {
1616
},
1717
openServiceOptionsElms: {
1818
serviceId: document.getElementById('open-service-options-serviceId') as HTMLSelectElement,
19-
view: document.getElementById('open-service-options-view') as HTMLSelectElement,
19+
vaultView: document.getElementById('open-service-options-vault-view') as HTMLSelectElement,
20+
myAccountView: document.getElementById('open-service-options-myaccount-view') as HTMLSelectElement,
2021
type: document.getElementById('open-service-options-type') as HTMLSelectElement,
2122
group: document.getElementById('open-service-options-group') as HTMLSelectElement,
2223
search: document.getElementById('open-service-options-search') as HTMLInputElement,
@@ -41,5 +42,6 @@ export default {
4142
openServiceSection: document.getElementById('open-service-section') as HTMLDivElement,
4243
logoutSection: document.getElementById('logout-section') as HTMLDivElement,
4344
tokenInfoSection: document.getElementById('token-info-section') as HTMLDivElement,
44-
vaultOptions: document.getElementById('vault-options') as HTMLDivElement
45+
pageVaultOptions: document.getElementById('page-vault-options') as HTMLDivElement,
46+
pageMyAccountOptions: document.getElementById('page-myaccount-options') as HTMLDivElement
4547
};

sample/src/index.html

+21-12
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ <h3>Login Link</h3>
163163
<option value="settings/email-preferences">settings/email-preferences</option>
164164
<option value="settings/delete-account">settings/delete-account</option>
165165
<option value="settings/update-email">settings/update-email</option>
166-
<option value="settings/update-email">settings/update-password</option>
166+
<option value="settings/update-password">settings/update-password</option>
167167
</select>
168168
</div>
169169
</p>
@@ -197,30 +197,39 @@ <h3>Token Information</h3>
197197
<section id="open-service-section">
198198
<h3>Open Service</h3>
199199
<p>
200-
<span style="color: red;">*</span>ServiceId, <small>Open a service by Id, current supported services are vault, my-account, link-kit </small>
200+
<span style="color: red;">*</span>ServiceId, <small>Open a service by Id, current supported services are vault, myaccount, link-kit </small>
201201
<div>
202202
<select id="open-service-options-serviceId">
203203
<option value="vault" default>vault</option>
204-
<option value="myaccount-settings">myaccount</option>
204+
<option value="myaccount">myaccount</option>
205205
<option value="link-kit">link-kit</option>
206206
</select>
207207
</div>
208208
</p>
209209

210-
<div id="vault-options">
211-
<span style="color: red;">*</span>View, <small>We provide a way to open the Vault's specific pages. </small>
210+
<div id="page-myaccount-options" style="display: none">
211+
<span style="color: red;">*</span>View, <small>We provide a way to open specific pages. </small>
212212
<div>
213-
<select id="open-service-options-view">
213+
<select id="open-service-options-myaccount-view">
214+
<option value="settings" default>settings</option>
215+
<option value="settings/authorized-applications">settings/authorized-applications</option>
216+
<option value="settings/change-language">settings/change-language</option>
217+
<option value="settings/email-preferences">settings/email-preferences</option>
218+
<option value="settings/delete-account">settings/delete-account</option>
219+
<option value="settings/update-email">settings/update-email</option>
220+
<option value="settings/update-password">settings/update-password</option>
221+
</select>
222+
</div>
223+
</div>
224+
225+
<div id="page-vault-options">
226+
<span style="color: red;">*</span>View, <small>We provide a way to open specific pages. </small>
227+
<div>
228+
<select id="open-service-options-vault-view">
214229
<option value="services-list" default>services-list</option>
215230
<option value="service-connection">service-connection</option>
216231
<option value="connection-setting">connection-setting</option>
217232
<option value="customer-support">customer-support</option>
218-
<option value="authorized-applications">authorized-applications</option>
219-
<option value="change-language">change-language</option>
220-
<option value="email-preferences">email-preferences</option>
221-
<option value="delete-account">delete-account</option>
222-
<option value="update-email">update-email</option>
223-
<option value="update-password">update-password</option>
224233
</select>
225234
</div>
226235

sample/src/index.ts

+24-17
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ elements.openServiceBtn.onclick = () => {
122122
.value as ServiceId;
123123

124124
if (serviceId === 'vault') {
125-
const view = openServiceOptionsElms.view.options[openServiceOptionsElms.view.selectedIndex].value as
125+
const view = openServiceOptionsElms.vaultView.options[openServiceOptionsElms.vaultView.selectedIndex].value as
126126
| 'services-list'
127127
| 'service-connection'
128128
| 'connection-setting'
@@ -163,14 +163,16 @@ elements.openServiceBtn.onclick = () => {
163163
}
164164
}
165165

166-
if (serviceId === 'myaccount-settings') {
167-
const view = openServiceOptionsElms.view.options[openServiceOptionsElms.view.selectedIndex].value as
168-
| 'authorized-applications'
169-
| 'change-language'
170-
| 'email-preferences'
171-
| 'delete-account'
172-
| 'update-email'
173-
| 'update-password';
166+
if (serviceId === 'myaccount') {
167+
const view = openServiceOptionsElms.myAccountView.options[openServiceOptionsElms.myAccountView.selectedIndex]
168+
.value as
169+
| 'settings'
170+
| 'settings/authorized-applications'
171+
| 'settings/change-language'
172+
| 'settings/email-preferences'
173+
| 'settings/delete-account'
174+
| 'settings/update-email'
175+
| 'settings/update-password';
174176

175177
OpenServicesConfigsOptions = { view };
176178
}
@@ -197,23 +199,28 @@ elements.sendLoginLinkBtn.onclick = async () => {
197199
sendLoginLinkBtn.disabled = false;
198200
};
199201

200-
// Helper, to switch the vault options, depends on openService's serviceId value
202+
// Helper, to switch the options, depends on openService's serviceId value
201203
elements.openServiceOptionsElms.serviceId.onchange = () => {
202-
const { openServiceOptionsElms, vaultOptions } = elements;
204+
const { openServiceOptionsElms, pageVaultOptions, pageMyAccountOptions } = elements;
203205
const selectedValue = openServiceOptionsElms.serviceId.options[openServiceOptionsElms.serviceId.selectedIndex].value;
204206

205-
if (selectedValue === 'vault' || selectedValue === 'myaccount-settings') {
206-
vaultOptions.style.display = 'block';
207+
pageVaultOptions.style.display = 'none';
208+
pageMyAccountOptions.style.display = 'none';
209+
210+
if (selectedValue === 'vault') {
211+
pageVaultOptions.style.display = 'block';
212+
return;
213+
}
214+
if (selectedValue === 'myaccount') {
215+
pageMyAccountOptions.style.display = 'block';
207216
return;
208217
}
209-
210-
vaultOptions.style.display = 'none';
211218
};
212219

213220
// Helper, To switch the options, depends on openService's view value for vault
214-
elements.openServiceOptionsElms.view.onchange = () => {
221+
elements.openServiceOptionsElms.vaultView.onchange = () => {
215222
const { openServiceOptionsElms } = elements;
216-
const selectedValue = openServiceOptionsElms.view.options[openServiceOptionsElms.view.selectedIndex].value;
223+
const selectedValue = openServiceOptionsElms.vaultView.options[openServiceOptionsElms.vaultView.selectedIndex].value;
217224

218225
const vaultServicesElms = document.getElementsByClassName('vault-services');
219226
for (let indx = 0; indx < vaultServicesElms.length; indx++) {

src/api/__tests__/open-service.test.ts

+20-5
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,32 @@ describe('api', () => {
1010
const open = (window.open = jest.fn());
1111
const clientId = 'clientId';
1212

13-
test('myaccount-settings', () => {
13+
test('myaccount', () => {
1414
open.mockClear();
1515

16-
openService(new MtLinkSdk().storedOptions, 'myaccount-settings');
16+
openService(new MtLinkSdk().storedOptions, 'myaccount');
1717

1818
expect(open).toBeCalledTimes(1);
1919

2020
const query = qs.stringify({
2121
configs: generateConfigs()
2222
});
23-
const url = `${MY_ACCOUNT_DOMAINS.production}/settings/?${query}`;
23+
const url = `${MY_ACCOUNT_DOMAINS.production}/?${query}`;
24+
25+
expect(open).toBeCalledWith(url, '_self', 'noreferrer');
26+
});
27+
28+
test('myaccount/change-language', () => {
29+
open.mockClear();
30+
31+
openService(new MtLinkSdk().storedOptions, 'myaccount', { view: 'settings/change-language' });
32+
33+
expect(open).toBeCalledTimes(1);
34+
35+
const query = qs.stringify({
36+
configs: generateConfigs()
37+
});
38+
const url = `${MY_ACCOUNT_DOMAINS.production}/settings/change-language?${query}`;
2439

2540
expect(open).toBeCalledWith(url, '_self', 'noreferrer');
2641
});
@@ -161,7 +176,7 @@ describe('api', () => {
161176
cobrandClientId
162177
});
163178

164-
openService(mtLinkSdk.storedOptions, 'myaccount-settings');
179+
openService(mtLinkSdk.storedOptions, 'myaccount');
165180

166181
expect(open).toBeCalledTimes(1);
167182

@@ -171,7 +186,7 @@ describe('api', () => {
171186
locale,
172187
configs: generateConfigs()
173188
});
174-
const url = `${MY_ACCOUNT_DOMAINS.production}/settings/?${query}`;
189+
const url = `${MY_ACCOUNT_DOMAINS.production}/?${query}`;
175190

176191
expect(open).toBeCalledWith(url, '_self', 'noreferrer');
177192
});

src/api/open-service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function openService(
2828
}
2929

3030
const { clientId, mode, cobrandClientId, locale } = storedOptions;
31-
const { isNewTab, view, ...rest } = options;
31+
const { isNewTab, view = '', ...rest } = options;
3232

3333
const getQueryValue = (needStringify = true): string | QueryData => {
3434
const query: QueryData = {
@@ -90,8 +90,8 @@ export default function openService(
9090

9191
break;
9292

93-
case 'myaccount-settings':
94-
openWindow(`${MY_ACCOUNT_DOMAINS[mode]}/settings/${view || ''}?${getQueryValue()}`, getIsTabValue(isNewTab));
93+
case 'myaccount':
94+
openWindow(`${MY_ACCOUNT_DOMAINS[mode]}/${view}?${getQueryValue()}`, getIsTabValue(isNewTab));
9595
break;
9696

9797
case 'link-kit':

src/typings.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,7 @@ export type ConnectionSettingType = { view?: 'connection-setting'; credentialId:
4848

4949
export type CustomerSupportType = { view?: 'customer-support' };
5050

51-
export type MyAccountPageType = {
52-
view?:
53-
| 'authorized-applications'
54-
| 'change-language'
55-
| 'email-preferences'
56-
| 'delete-account'
57-
| 'update-email'
58-
| 'update-password';
59-
};
51+
export type MyAccountPageType = { view?: LoginLinkTo };
6052

6153
export type OpenServicesConfigsOptions = ConfigsOptions &
6254
(ServicesListType | ServiceConnectionType | ConnectionSettingType | CustomerSupportType | MyAccountPageType);
@@ -101,7 +93,7 @@ export type OnboardOptions = Omit<
10193
'authAction'
10294
>;
10395

104-
export type ServiceId = string | 'vault' | 'myaccount-settings' | 'linkkit';
96+
export type ServiceId = string | 'vault' | 'myaccount' | 'linkkit';
10597

10698
export type LoginLinkTo =
10799
| string

0 commit comments

Comments
 (0)