Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/components/application/detail-header.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
@text="Edit"
@variant="light"
@class="btn--xs"
@disabled={{this.isEditDisabled}}
@onClick={{this.editApplication}}
@test="edit-button"
/>
Expand Down
43 changes: 33 additions & 10 deletions app/components/application/detail-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,21 @@ import { TOAST_OPTIONS } from '../../constants/toast-options';
import { NUDGE_APPLICATION_URL } from '../../constants/apis';
import apiRequest from '../../utils/api-request';

const TWENTY_FOUR_HOURS = 24 * 60 * 60 * 1000;

function isWithinCooldown(timestamp, cooldownMs = TWENTY_FOUR_HOURS) {
if (!timestamp) {
return false;
}

const now = Date.now();
const time = new Date(timestamp).getTime();

return now - time < cooldownMs;
}

export default class DetailHeader extends Component {
@service router;
@service toast;

@tracked isLoading = false;
Expand Down Expand Up @@ -56,17 +70,22 @@ export default class DetailHeader extends Component {
return this.args.lastNudgeAt ?? this.application?.lastNudgeAt ?? null;
}

get lastEditAt() {
return this.application?.lastEditAt ?? null;
}

get isNudgeDisabled() {
if (this.isLoading || this.status !== 'pending') {
return true;
}
if (!this.lastNudgeAt) {
return false;
return isWithinCooldown(this.lastNudgeAt);
}

get isEditDisabled() {
if (this.isLoading) {
return true;
}
const now = Date.now();
const lastNudgeTime = new Date(this.lastNudgeAt).getTime();
const TWENTY_FOUR_HOURS = 24 * 60 * 60 * 1000;
return now - lastNudgeTime < TWENTY_FOUR_HOURS;
return isWithinCooldown(this.lastEditAt);
}

get socialLinks() {
Expand Down Expand Up @@ -129,13 +148,17 @@ export default class DetailHeader extends Component {

@action
editApplication() {
//ToDo: Implement logic for edit application here
console.log('edit application');
this.router.transitionTo('join', {
queryParams: {
edit: true,
dev: true,
step: 1,
},
});
}

@action
navigateToDashboard() {
//ToDo: Navigate to dashboard site for admin actions
console.log('navigate to dashboard');
this.router.transitionTo(`/intro?id=${this.userDetails?.id}`);
}
}
70 changes: 58 additions & 12 deletions app/components/new-join-steps/base-step.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,85 @@
import { action } from '@ember/object';
import Component from '@glimmer/component';
import { service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { debounceTask, runTask } from 'ember-lifeline';
import { JOIN_DEBOUNCE_TIME } from '../../constants/join';
import { USER_ROLE_MAP } from '../../constants/new-join-form';
import { validateWordCount } from '../../utils/validator';
import { getLocalStorageItem, setLocalStorageItem } from '../../utils/storage';

export default class BaseStepComponent extends Component {
@service onboarding;

stepValidation = {};

@tracked data = {};
@tracked errorMessage = {};
@tracked wordCount = {};

get storageKey() {
return '';
}

postLoadInitialize() {}

STEP_FORM_DATA_MAPPING = {
newStepOneData: (app) => ({
firstName: app.biodata?.firstName || '',
lastName: app.biodata?.lastName || '',
city: app.location?.city || '',
state: app.location?.state || '',
country: app.location?.country || '',
role:
Object.keys(USER_ROLE_MAP).find(
(key) => USER_ROLE_MAP[key] === app.role,
) || '',
imageUrl: app.imageUrl || '',
}),
newStepTwoData: (app) => ({
institution: app.professional?.institution || '',
skills: app.professional?.skills || '',
introduction: app.intro?.introduction || '',
}),
newStepThreeData: (app) => ({
forFun: app.intro?.forFun || '',
funFact: app.intro?.funFact || '',
}),
newStepFourData: (app) => ({
phoneNo: app.socialLink?.phoneNo || '',
twitter: app.socialLink?.twitter || '',
linkedin: app.socialLink?.linkedin || '',
instagram: app.socialLink?.instagram || '',
github: app.socialLink?.github || '',
peerlist: app.socialLink?.peerlist || '',
behance: app.socialLink?.behance || '',
dribble: app.socialLink?.dribble || '',
}),
newStepFiveData: (app) => ({
whyRds: app.intro?.whyRds || '',
foundFrom: app.foundFrom || '',
numberOfHours: app.intro?.numberOfHours || '',
}),
};

constructor(...args) {
super(...args);
this.initializeFormState();
}

initializeFormState() {
let saved = {};
try {
const stored = getLocalStorageItem(this.storageKey, '{}');
saved = stored ? JSON.parse(stored) : {};
} catch (e) {
console.warn('Failed to parse stored form data:', e);
saved = {};
const storedData = getLocalStorageItem(this.storageKey, '{}');
let initialFormData = storedData ? JSON.parse(storedData) : {};

if (
Object.keys(initialFormData).length === 0 &&
this.onboarding.applicationData
) {
const stepDataMapper = this.STEP_FORM_DATA_MAPPING[this.storageKey];

if (stepDataMapper) {
initialFormData = stepDataMapper(this.onboarding.applicationData);
setLocalStorageItem(this.storageKey, JSON.stringify(initialFormData));
}
}
this.data = saved;

this.data = initialFormData;

this.errorMessage = Object.fromEntries(
Object.keys(this.stepValidation).map((k) => [k, '']),
Expand Down
4 changes: 3 additions & 1 deletion app/components/new-join-steps/new-step-five.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
import { heardFrom } from '../../constants/social-data';

export default class NewStepFiveComponent extends BaseStepComponent {
storageKey = STEP_DATA_STORAGE_KEY.stepFive;
get storageKey() {
return STEP_DATA_STORAGE_KEY.stepFive;
}
heardFrom = heardFrom;

stepValidation = {
Expand Down
4 changes: 3 additions & 1 deletion app/components/new-join-steps/new-step-four.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
import { phoneNumberRegex } from '../../constants/regex';

export default class NewStepFourComponent extends BaseStepComponent {
storageKey = STEP_DATA_STORAGE_KEY.stepFour;
get storageKey() {
return STEP_DATA_STORAGE_KEY.stepFour;
}

stepValidation = {
phoneNo: NEW_STEP_LIMITS.stepFour.phoneNo,
Expand Down
9 changes: 6 additions & 3 deletions app/components/new-join-steps/new-step-six.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,13 @@
<span class="review-field__label">Institution/Company:</span>
<span
class="review-field__value
{{unless this.stepData.two.college 'review-field__value--missing'}}"
{{unless
this.stepData.two.institution
'review-field__value--missing'
}}"
>
{{#if this.stepData.two.college}}
{{this.stepData.two.college}}
{{#if this.stepData.two.institution}}
{{this.stepData.two.institution}}
{{else}}
Not provided
{{/if}}
Expand Down
4 changes: 3 additions & 1 deletion app/components/new-join-steps/new-step-three.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
} from '../../constants/new-join-form';

export default class NewStepThreeComponent extends BaseStepComponent {
storageKey = STEP_DATA_STORAGE_KEY.stepThree;
get storageKey() {
return STEP_DATA_STORAGE_KEY.stepThree;
}
stepValidation = {
forFun: NEW_STEP_LIMITS.stepThree.forFun,
funFact: NEW_STEP_LIMITS.stepThree.funFact,
Expand Down
10 changes: 5 additions & 5 deletions app/components/new-join-steps/new-step-two.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
<div class="form-grid__item">
<Reusables::InputBox
@field="Your institution/company"
@name="college"
@name="institution"
@placeHolder="Institution or company name"
@type="text"
@required={{true}}
@value={{this.data.college}}
@value={{this.data.institution}}
@onInput={{this.inputHandler}}
/>
{{#if this.errorMessage.college}}
{{#if this.errorMessage.institution}}
<div
class="error__message"
data-test-error="college"
>{{this.errorMessage.college}}</div>
data-test-error="institution"
>{{this.errorMessage.institution}}</div>
{{/if}}
</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions app/components/new-join-steps/new-step-two.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import {
} from '../../constants/new-join-form';

export default class NewStepTwoComponent extends BaseStepComponent {
storageKey = STEP_DATA_STORAGE_KEY.stepTwo;
get storageKey() {
return STEP_DATA_STORAGE_KEY.stepTwo;
}
stepValidation = {
skills: NEW_STEP_LIMITS.stepTwo.skills,
college: NEW_STEP_LIMITS.stepTwo.college,
institution: NEW_STEP_LIMITS.stepTwo.institution,
introduction: NEW_STEP_LIMITS.stepTwo.introduction,
};
}
Loading