Skip to content

Commit

Permalink
feat: add step2 on identity linking page
Browse files Browse the repository at this point in the history
  • Loading branch information
tejaskh3 committed Jan 4, 2025
1 parent 9044a36 commit 60b503d
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 1 deletion.
21 changes: 21 additions & 0 deletions app/components/identity/step2.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class='identity-box-heading' data-test-step2-heading>Step 2: Profile
Service URL</div>
<div class='identity-box-desc' data-test-step2-desc>Set the chaincode on your
profile service, deploy it and enter your profile service URL.</div>
<label>
<Input
@value={{this.profileURL}}
class='identity-box-input'
placeholder='E.g.: https://my-profile-service.com'
data-test-step2-input
/>
</label>
{{#if this.profileURL}}
<button
class='identity-next-button'
data-test-step2-next-button
type='button'
{{on 'click' this.handleNext}}
>
{{#if this.savingURL}}<div class='loader'></div>{{else}}Next{{/if}}</button>
{{/if}}
73 changes: 73 additions & 0 deletions app/components/identity/step2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { toastNotificationTimeoutOptions } from '../../constants/toast-notification';
import { APPS } from '../../constants/urls';

const BASE_URL = APPS.API_BACKEND;

export default class Step2Component extends Component {
@tracked profileURL = this.args.profileURL || '';
@tracked savingURL = false;
@service toast;

@action async handleNext() {
const isValidUrl = (str) => {
try {
const newUrl = new URL(str);
return newUrl.protocol === 'https:';
} catch (err) {
return false;
}
};
if (this.profileURL) {
if (isValidUrl(this.profileURL)) {
if (this.savingURL === false) {
if (this.profileURL === this.args.profileURL) {
this.args.setState('step3');
return;
}
this.savingURL = true;
try {
const response = await fetch(`${BASE_URL}/users/profileURL`, {
method: 'PATCH',
body: JSON.stringify({ profileURL: this.profileURL }),
headers: {
'Content-Type': 'application/json',
},
credentials: 'include',
});
if (response.ok) {
this.toast.info(
'Updated profile URL!!',
'',
toastNotificationTimeoutOptions,
);
this.args.setState('step3');
} else {
this.toast.error(
'Something went wrong. Please check console errors.',
'',
toastNotificationTimeoutOptions,
);
}
} catch (error) {
console.error(error);
this.toast.error(
'Something went wrong. Please check console errors.',
'',
toastNotificationTimeoutOptions,
);
} finally {
this.savingURL = false;
}
}
} else {
alert(
'Invalid URL! Make sure you entered the correct https profile URL.',
);
}
}
}
}
3 changes: 2 additions & 1 deletion app/controllers/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ export default class IdentityController extends Controller {

@tracked userData = null;
@tracked state = 'getStarted';

@tracked profileURL = null;
constructor() {
super(...arguments);
this.userData = this.login.userData;
this.state = this.initialState;
this.profileURL = this.userData?.profileURL;
}

get initialState() {
Expand Down
24 changes: 24 additions & 0 deletions app/styles/identity.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,30 @@
bottom: 8%;
}

.identity-box-input {
border: 1px solid rgb(0 0 0 / 50%);
background: #fff;
width: 50%;
margin-top: 16px;
padding: 8px;
color: #0000af;
font-family: Inter, sans-serif;
font-size: 16px;
font-style: normal;
font-weight: 500;
line-height: normal;
border-radius: 8px;
}

.identity-box-input::placeholder {
color: #808080;
font-family: Inter, sans-serif;
font-size: 14px;
font-style: normal;
font-weight: 400;
line-height: normal;
}

@media (width <= 460px) {
.identity-box-input {
width: 90%;
Expand Down
5 changes: 5 additions & 0 deletions app/templates/identity.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
<Identity::GetStarted @setState={{this.setState}} />
{{else if (eq this.state 'step1')}}
<Identity::Step1 @setState={{this.setState}} />
{{else if (eq this.state 'step2')}}
<Identity::Step2
@setState={{this.setState}}
@profileURL={{this.profileURL}}
/>
{{/if}}
</div>

Expand Down

0 comments on commit 60b503d

Please sign in to comment.