@@ -6,11 +6,19 @@ import classNames from 'classnames'
66import { Button , IconOutline , PageDivider } from '~/libs/ui'
77import { EnvironmentConfig } from '~/config'
88
9- import { useAutoSavePersonalization , useAutoSavePersonalizationType } from '../../hooks/useAutoSavePersonalization'
109import { ProgressBar } from '../../components/progress-bar'
10+ import {
11+ useAutoSaveMemberDescription ,
12+ useAutoSaveMemberDescriptionType ,
13+ } from '../../hooks/useAutoSaveMemberDescription'
14+ import {
15+ useAutoSavePersonalization ,
16+ useAutoSavePersonalizationType ,
17+ } from '../../hooks/useAutoSavePersonalization'
1118import {
1219 createMemberPersonalizations ,
1320 setMemberPhotoUrl ,
21+ updateMemberDescription ,
1422 updateMemberPersonalizations ,
1523 updateMemberPhotoUrl ,
1624} from '../../redux/actions/member'
@@ -31,11 +39,14 @@ const PagePersonalizationContent: FC<{
3139 createMemberPersonalizations : ( infos : PersonalizationInfo [ ] ) => void
3240 setMemberPhotoUrl : ( photoUrl : string ) => void
3341 updateMemberPhotoUrl : ( photoUrl : string ) => void
42+ updateMemberDescription : ( photoUrl : string ) => void
3443 loadingMemberTraits : boolean
44+ loadingMemberInfo : boolean
3545} > = props => {
3646 const navigate : any = useNavigate ( )
3747
3848 const shouldSavingData : MutableRefObject < boolean > = useRef < boolean > ( false )
49+ const shouldSavingMemberData : MutableRefObject < boolean > = useRef < boolean > ( false )
3950 const shouldNavigateTo : MutableRefObject < string > = useRef < string > ( '' )
4051
4152 const {
@@ -49,16 +60,42 @@ const PagePersonalizationContent: FC<{
4960 shouldSavingData ,
5061 )
5162
63+ const {
64+ loading : loadingMemberInfo ,
65+ description,
66+ setDescription,
67+ } : useAutoSaveMemberDescriptionType = useAutoSaveMemberDescription (
68+ props . memberInfo ,
69+ props . updateMemberDescription ,
70+ shouldSavingMemberData ,
71+ )
72+
5273 useEffect ( ( ) => {
53- if ( ! loading && ! shouldSavingData . current && ! ! shouldNavigateTo . current ) {
74+ if (
75+ ! loading
76+ && ! loadingMemberInfo
77+ && ! shouldSavingData . current
78+ && ! shouldSavingMemberData . current
79+ && ! ! shouldNavigateTo . current
80+ ) {
5481 if ( shouldNavigateTo . current . startsWith ( '../' ) ) {
5582 navigate ( shouldNavigateTo . current )
5683 } else {
5784 window . location . href = shouldNavigateTo . current
5885 }
5986 }
6087 /* eslint-disable react-hooks/exhaustive-deps */
61- } , [ loading ] )
88+ } , [ loading , loadingMemberInfo ] )
89+
90+ function nextPage ( pageUrl : string ) : void {
91+ if ( loading || loadingMemberInfo ) {
92+ shouldNavigateTo . current = pageUrl
93+ } else if ( pageUrl . startsWith ( '../' ) ) {
94+ navigate ( pageUrl )
95+ } else {
96+ window . location . href = pageUrl
97+ }
98+ }
6299
63100 return (
64101 < div className = { classNames ( 'd-flex flex-column' , styles . container ) } >
@@ -93,16 +130,13 @@ const PagePersonalizationContent: FC<{
93130 < InputTextareaAutoSave
94131 name = 'shortBio'
95132 label = 'Bio'
96- value = { personalizationInfo ?. shortBio || '' }
133+ value = { description || '' }
97134 onChange = { function onChange ( value : string | undefined ) {
98- setPersonalizationInfo ( {
99- ...( personalizationInfo || blankPersonalizationInfo ) ,
100- shortBio : value || '' ,
101- } )
135+ setDescription ( value || '' )
102136 } }
103137 placeholder = 'Share something that makes you, you.'
104138 tabIndex = { 0 }
105- disabled = { props . loadingMemberTraits }
139+ disabled = { props . loadingMemberInfo }
106140 />
107141 </ div >
108142 </ div >
@@ -119,26 +153,21 @@ const PagePersonalizationContent: FC<{
119153 secondary
120154 iconToLeft
121155 icon = { IconOutline . ChevronLeftIcon }
156+ disabled = { ! ! shouldNavigateTo . current }
122157 onClick = { function previousPage ( ) {
123- if ( loading ) {
124- shouldNavigateTo . current = '../educations'
125- } else {
126- navigate ( '../educations' )
127- }
158+ nextPage ( '../educations' )
128159 } }
129160 />
130161 < Button
131162 size = 'lg'
132163 primary
133164 iconToLeft
134- onClick = { function nextPage ( ) {
135- if ( loading ) {
136- shouldNavigateTo . current
137- = `${ EnvironmentConfig . USER_PROFILE_URL } /${ props . memberInfo ?. handle } `
138- } else {
139- window . location . href
140- = `${ EnvironmentConfig . USER_PROFILE_URL } /${ props . memberInfo ?. handle } `
141- }
165+ disabled = { ! ! shouldNavigateTo . current }
166+ onClick = { function onClick ( ) {
167+ nextPage (
168+ `${ EnvironmentConfig . USER_PROFILE_URL } /${ props . memberInfo ?. handle } `
169+ + '?edit-mode=onboardingCompleted' ,
170+ )
142171 } }
143172 >
144173 next
@@ -151,11 +180,13 @@ const PagePersonalizationContent: FC<{
151180const mapStateToProps : any = ( state : any ) => {
152181 const {
153182 loadingMemberTraits,
183+ loadingMemberInfo,
154184 personalization,
155185 memberInfo,
156186 } : any = state . member
157187
158188 return {
189+ loadingMemberInfo,
159190 loadingMemberTraits,
160191 memberInfo,
161192 reduxPersonalization : personalization ,
@@ -165,6 +196,7 @@ const mapStateToProps: any = (state: any) => {
165196const mapDispatchToProps : any = {
166197 createMemberPersonalizations,
167198 setMemberPhotoUrl,
199+ updateMemberDescription,
168200 updateMemberPersonalizations,
169201 updateMemberPhotoUrl,
170202}
0 commit comments