|
1 | 1 | import { action } from '@ember/object'; |
2 | 2 | import Component from '@glimmer/component'; |
| 3 | +import { service } from '@ember/service'; |
3 | 4 | import { tracked } from '@glimmer/tracking'; |
4 | 5 | import { debounceTask, runTask } from 'ember-lifeline'; |
5 | 6 | import { JOIN_DEBOUNCE_TIME } from '../../constants/join'; |
| 7 | +import { USER_ROLE_MAP } from '../../constants/new-join-form'; |
6 | 8 | import { validateWordCount } from '../../utils/validator'; |
7 | 9 | import { getLocalStorageItem, setLocalStorageItem } from '../../utils/storage'; |
8 | 10 |
|
9 | 11 | export default class BaseStepComponent extends Component { |
| 12 | + @service onboarding; |
| 13 | + |
10 | 14 | stepValidation = {}; |
11 | 15 |
|
12 | 16 | @tracked data = {}; |
13 | 17 | @tracked errorMessage = {}; |
14 | 18 | @tracked wordCount = {}; |
15 | 19 |
|
16 | | - get storageKey() { |
17 | | - return ''; |
18 | | - } |
19 | | - |
20 | 20 | postLoadInitialize() {} |
21 | 21 |
|
| 22 | + STEP_FORM_DATA_MAPPING = { |
| 23 | + newStepOneData: (app) => ({ |
| 24 | + firstName: app.biodata?.firstName || '', |
| 25 | + lastName: app.biodata?.lastName || '', |
| 26 | + city: app.location?.city || '', |
| 27 | + state: app.location?.state || '', |
| 28 | + country: app.location?.country || '', |
| 29 | + role: |
| 30 | + Object.keys(USER_ROLE_MAP).find( |
| 31 | + (key) => USER_ROLE_MAP[key] === app.role, |
| 32 | + ) || '', |
| 33 | + imageUrl: app.imageUrl || '', |
| 34 | + }), |
| 35 | + newStepTwoData: (app) => ({ |
| 36 | + institution: app.professional?.institution || '', |
| 37 | + skills: app.professional?.skills || '', |
| 38 | + introduction: app.intro?.introduction || '', |
| 39 | + }), |
| 40 | + newStepThreeData: (app) => ({ |
| 41 | + forFun: app.intro?.forFun || '', |
| 42 | + funFact: app.intro?.funFact || '', |
| 43 | + }), |
| 44 | + newStepFourData: (app) => ({ |
| 45 | + phoneNo: app.socialLink?.phoneNo || '', |
| 46 | + twitter: app.socialLink?.twitter || '', |
| 47 | + linkedin: app.socialLink?.linkedin || '', |
| 48 | + instagram: app.socialLink?.instagram || '', |
| 49 | + github: app.socialLink?.github || '', |
| 50 | + peerlist: app.socialLink?.peerlist || '', |
| 51 | + behance: app.socialLink?.behance || '', |
| 52 | + dribble: app.socialLink?.dribble || '', |
| 53 | + }), |
| 54 | + newStepFiveData: (app) => ({ |
| 55 | + whyRds: app.intro?.whyRds || '', |
| 56 | + foundFrom: app.foundFrom || '', |
| 57 | + numberOfHours: app.intro?.numberOfHours || '', |
| 58 | + }), |
| 59 | + }; |
| 60 | + |
22 | 61 | constructor(...args) { |
23 | 62 | super(...args); |
24 | 63 | this.initializeFormState(); |
25 | 64 | } |
26 | 65 |
|
27 | 66 | initializeFormState() { |
28 | | - let saved = {}; |
29 | | - try { |
30 | | - const stored = getLocalStorageItem(this.storageKey, '{}'); |
31 | | - saved = stored ? JSON.parse(stored) : {}; |
32 | | - } catch (e) { |
33 | | - console.warn('Failed to parse stored form data:', e); |
34 | | - saved = {}; |
| 67 | + const storedData = getLocalStorageItem(this.storageKey, '{}'); |
| 68 | + let initialFormData = storedData ? JSON.parse(storedData) : {}; |
| 69 | + |
| 70 | + if ( |
| 71 | + Object.keys(initialFormData).length === 0 && |
| 72 | + this.onboarding.applicationData |
| 73 | + ) { |
| 74 | + const stepDataMapper = this.STEP_FORM_DATA_MAPPING[this.storageKey]; |
| 75 | + |
| 76 | + if (stepDataMapper) { |
| 77 | + initialFormData = stepDataMapper(this.onboarding.applicationData); |
| 78 | + setLocalStorageItem(this.storageKey, JSON.stringify(initialFormData)); |
| 79 | + } |
35 | 80 | } |
36 | | - this.data = saved; |
| 81 | + |
| 82 | + this.data = initialFormData; |
37 | 83 |
|
38 | 84 | this.errorMessage = Object.fromEntries( |
39 | 85 | Object.keys(this.stepValidation).map((k) => [k, '']), |
|
0 commit comments