@@ -6,9 +6,10 @@ import Router from 'next/router'
66import descriptionPopup from './description-popup'
77import { Formik , Field , useField , Form , ErrorMessage } from 'formik'
88import { getOrgMemberAttributes , getTeamMemberAttributes , getMyProfile , setMyProfile } from '../lib/profiles-api'
9+ import { getOrg } from '../lib/org-api'
910import { getTeam } from '../lib/teams-api'
1011import Button from '../components/button'
11- import { propOr } from 'ramda'
12+ import { propOr , prop } from 'ramda'
1213
1314function GenderSelectField ( props ) {
1415 const [ field , meta , { setValue, setTouched } ] = useField ( props . name )
@@ -88,31 +89,47 @@ export default class ProfileForm extends Component {
8889 memberAttributes : [ ] ,
8990 orgAttributes : [ ] ,
9091 profileValues : { } ,
92+ consentChecked : true ,
9193 loading : true ,
9294 error : undefined
9395 }
96+
97+ this . setConsentChecked = this . setConsentChecked . bind ( this )
9498 }
9599
96100 async componentDidMount ( ) {
97101 this . getProfileForm ( )
98102 }
99103
104+ setConsentChecked ( checked ) {
105+ this . setState ( {
106+ consentChecked : checked
107+ } )
108+ }
109+
100110 async getProfileForm ( ) {
101111 const { id } = this . props
102112 try {
103113 let memberAttributes = [ ]
104114 let orgAttributes = [ ]
115+ let org = { }
116+ let consentChecked = true
105117 const returnUrl = `/teams/${ this . props . id } `
106118 const team = await getTeam ( id )
107119 if ( team . org ) {
120+ org = await getOrg ( team . org . organization_id )
108121 orgAttributes = await getOrgMemberAttributes ( team . org . organization_id )
122+ consentChecked = ! ( org && org . privacy_policy )
109123 }
110124 memberAttributes = await getTeamMemberAttributes ( id )
111125 let profileValues = ( await getMyProfile ( ) ) . tags
112126 this . setState ( {
113127 id,
114128 returnUrl,
129+ team,
115130 memberAttributes,
131+ consentChecked,
132+ org,
116133 orgAttributes,
117134 profileValues,
118135 loading : false
@@ -127,7 +144,8 @@ export default class ProfileForm extends Component {
127144 }
128145
129146 render ( ) {
130- let { memberAttributes, orgAttributes, profileValues, returnUrl, loading } = this . state
147+ let { memberAttributes, orgAttributes, org, team, profileValues, returnUrl, consentChecked, loading } = this . state
148+ profileValues = profileValues || { }
131149
132150 if ( loading ) {
133151 return (
@@ -185,9 +203,12 @@ export default class ProfileForm extends Component {
185203 } )
186204 const yupSchema = Yup . object ( ) . shape ( schema )
187205
206+ const teamName = prop ( 'name' , team ) || 'team'
207+ const orgName = prop ( 'name' , org ) || 'org'
208+
188209 return (
189210 < article className = 'inner page' >
190- < h1 > Add Your Profile </ h1 >
211+ < h1 > Edit your profile details </ h1 >
191212 < Formik
192213 enableReinitialize
193214 validateOnBlur
@@ -215,7 +236,7 @@ export default class ProfileForm extends Component {
215236 < Form >
216237 { orgAttributes . length > 0
217238 ? < >
218- < h2 > Org Profile </ h2 >
239+ < h2 > Details for < b > { orgName } </ b > </ h2 >
219240 { orgAttributes . map ( attribute => {
220241 return < div className = 'form-control form-control__vertical' >
221242 < label > { attribute . name }
@@ -244,7 +265,7 @@ export default class ProfileForm extends Component {
244265 </ >
245266 : ''
246267 }
247- < h2 > Team Profile </ h2 >
268+ < h2 > Details for < b > { teamName } </ b > </ h2 >
248269 { memberAttributes . length > 0 ? memberAttributes . map ( attribute => {
249270 return < div className = 'form-control form-control__vertical' >
250271 < label > { attribute . name }
@@ -272,9 +293,22 @@ export default class ProfileForm extends Component {
272293 } )
273294 : 'No profile form to fill yet'
274295 }
296+ { org && org . privacy_policy
297+ ? < div >
298+ < h2 > Privacy Policy</ h2 >
299+ < div style = { { maxHeight : '100px' , width : '80%' , overflow : 'scroll' , marginBottom : '1rem' } } >
300+ { org . privacy_policy . body }
301+ </ div >
302+ < div style = { { maxHeight : '100px' , width : '80%' , overflow : 'scroll' } } >
303+ < input type = 'checkbox' checked = { consentChecked } onChange = { e => this . setConsentChecked ( e . target . checked ) } />
304+ { org . privacy_policy . consentText }
305+ </ div >
306+ </ div >
307+ : < div />
308+ }
275309 { status && status . msg && < div > { status . msg } </ div > }
276- < div style = { { marginTop : '1rem' } } className = 'form-control form-control__vertical' >
277- < Button type = 'submit' variant = 'submit' disabled = { isSubmitting } >
310+ < div style = { { marginTop : '1rem' } } className = 'form-control form-control__vertical' >
311+ < Button type = 'submit' variant = 'submit' disabled = { ! consentChecked || isSubmitting } >
278312 { addProfileText }
279313 </ Button >
280314 </ div >
0 commit comments