Skip to content

Commit

Permalink
Merge pull request #575 from Real-Dev-Squad/develop
Browse files Browse the repository at this point in the history
Dev to main
  • Loading branch information
lakshayman authored Feb 16, 2024
2 parents 1339f6f + 9901f9b commit 9a52847
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/components/profile-field.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
placeholder={{@placeholder}}
class="profile-field-input"
required={{@required}}
disabled={{@isDeveloper}}
{{on 'input' (fn this.inputFieldChanged)}}
{{on 'blur' (fn this.checkInputValidation)}}
/>
Expand Down
5 changes: 5 additions & 0 deletions app/routes/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ export default class ProfileRoute extends Route {
@service toast;
async model() {
try {
const res = await fetch(`${ENV.BASE_API_URL}/users/isDeveloper`, {
credentials: 'include',
});
const { developerRoleExistsOnUser } = await res.json();
const response = await fetch(`${ENV.BASE_API_URL}/users/self`, {
credentials: 'include',
});
const userData = await response.json();
if (response.status === 401) {
throw new Error('You are not logged in. Please login to continue.');
}
userData.isDeveloper = developerRoleExistsOnUser;
return userData;
} catch (error) {
console.error(error.message);
Expand Down
11 changes: 11 additions & 0 deletions app/styles/profile.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,24 @@
border-color: var(--profile-input-outline-clr);
}

.profile-page-error {
text-align: center;
color: red;
}

.profile-field-input {
padding: 0 1.25rem;
border: none;
background: none;
outline: none;
}

.profile-field-input:disabled {
opacity: 0.6;
cursor: not-allowed;
pointer-events: none;
}

.profile-field-input:active {
border-color: var(--profile-input-outline-clr);
}
Expand Down
43 changes: 33 additions & 10 deletions app/templates/profile.hbs
Original file line number Diff line number Diff line change
@@ -1,35 +1,58 @@
{{page-title 'Profile'}}

<div class="profile-container">
<form class="profile-form" {{on 'submit' (fn this.handleSubmit)}}>
<div class='profile-container'>
<form class='profile-form' {{on 'submit' (fn this.handleSubmit)}}>
<div class='picture_container'>
{{#if @model.picture.url}}
<img class='user__pic' src={{@model.picture.url}} alt='user profile ' />
<img class='user__pic' src={{@model.picture.url}} alt='user profile ' />
{{else}}
<img class='user__pic' src={{'dummyProfilePicture.png'}} alt='user profile ' />
<img
class='user__pic'
src={{'dummyProfilePicture.png'}}
alt='user profile '
/>
{{/if}}
<Button @onClick={{this.handleShowEditProfilePictureModal}} @class='edit-btn btn' @data-test-btn='edit'>
<Button
@onClick={{this.handleShowEditProfilePictureModal}}
@class='edit-btn btn'
@data-test-btn='edit'
>
Update Picture
</Button>
</div>
<div class='profile-form-grid'>
{{#if (get @model 'isDeveloper')}}
<p class='profile-page-error'>You can't update the profile data from UI.
You have to create a profile service(if not created yet). Find more
details about profile service
<a
href='https://github.com/Real-Dev-Squad/sample-profile-service'
target='_blank'
rel="noopener noreferrer"
>here</a>.</p>
{{/if}}
{{#each this.fields as |field|}}
<ProfileField
@id={{field.id}}
<ProfileField
@id={{field.id}}
@type={{field.type}}
@value={{get @model field.id}}
@placeholder={{field.placeholder}}
@placeholder={{field.placeholder}}
@label={{field.label}}
@icon_url={{field.icon_url}}
@icon_url={{field.icon_url}}
@errorMessage={{field.errorMessage}}
@showError={{field.showError}}
@required={{field.required}}
@onChange={{this.handleFieldChange}}
@onBlur={{this.handleFieldValidation}}
@isDeveloper={{get @model 'isDeveloper'}}
/>
{{/each}}
</div>
<button type="submit" class="profile-form-submit" disabled={{this.isSubmitDisabled}}>Submit</button>
<button
type='submit'
class='profile-form-submit'
disabled={{this.isSubmitDisabled}}
>Submit</button>
</form>
</div>

Expand Down
54 changes: 54 additions & 0 deletions tests/integration/components/profile-field-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,58 @@ module('Integration | Component | profile-field', function (hooks) {
assert.dom('[data-test-profile-field]').hasClass('profile-field-error');
assert.dom('[data-test-profile-field-error]').hasText(this.errorMessage);
});

test('disabled profile field renders when isDeveloper is true', async function (assert) {
this.setProperties({
label: 'First Name*',
icon_url: 'icons/user.svg',
isDeveloper: true,
});

await render(hbs`
<ProfileField
@label={{this.label}}
@icon_url={{this.icon_url}}
@isDeveloper={{this.isDeveloper}}
/>
`);

assert.dom('[data-test-profile-field-label]').hasText(this.label);
assert
.dom('[data-test-profile-field-icon]')
.exists()
.hasAttribute('src', this.icon_url);
assert
.dom('[data-test-profile-field-input]')
.hasProperty('disabled', true)
.exists();
assert.dom('[data-test-profile-field-error]').exists();
});

test('profile field renders when isDeveloper is false', async function (assert) {
this.setProperties({
label: 'First Name*',
icon_url: 'icons/user.svg',
isDeveloper: false,
});

await render(hbs`
<ProfileField
@label={{this.label}}
@icon_url={{this.icon_url}}
@isDeveloper={{this.isDeveloper}}
/>
`);

assert.dom('[data-test-profile-field-label]').hasText(this.label);
assert
.dom('[data-test-profile-field-icon]')
.exists()
.hasAttribute('src', this.icon_url);
assert
.dom('[data-test-profile-field-input]')
.hasProperty('disabled', false)
.exists();
assert.dom('[data-test-profile-field-error]').exists();
});
});

0 comments on commit 9a52847

Please sign in to comment.