-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add step2 on identity linking page
- Loading branch information
Showing
5 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.', | ||
); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters