Skip to content

Commit

Permalink
conditionals for Coach Only functions; #56
Browse files Browse the repository at this point in the history
  • Loading branch information
veeepi committed Apr 16, 2021
1 parent d308cbd commit cf9d2ba
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
16 changes: 10 additions & 6 deletions src/components/atoms/Action.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,16 @@ export default function SessionAction({action, authUser, dataUser}) {
<IconButton className={classes.dataButton} disabled={!actionEditMode} onClick={() => setStress(stress+1)}><AddCircleTwoToneIcon fontSize="small" className={classes.dataIcon} /></IconButton>
</Box>
</Box>
<Box className={classes.actionButtons}>
{/* Coach Only */}
<Button className={classes.buttonSecondary} disabled={!ownerCoach} onClick={() => setActionEditMode(!actionEditMode)} >{actionEditMode ? 'done edit' : 'EDIT'}</Button>
<TextField className={classes.orderIndex} disabled={!actionEditMode} id="orderIndex" label="order index" value={orderIndex} onChange={(e) => setOrderIndex(e.target.value)} />
<Button className={classes.buttonPrimary} disabled={!ownerCoach} onClick={(e) => saveAction(e)} >DONE</Button>
</Box>
{
dataUser.userType === "coach" &&
<Box className={classes.actionButtons}>
{/* Coach Only */}
<Button className={classes.buttonSecondary} disabled={!ownerCoach} onClick={() => setActionEditMode(!actionEditMode)} >{actionEditMode ? 'done edit' : 'EDIT'}</Button>
<TextField className={classes.orderIndex} disabled={!actionEditMode} id="orderIndex" label="order index" value={orderIndex} onChange={(e) => setOrderIndex(e.target.value)} />
<Button className={classes.buttonPrimary} disabled={!ownerCoach} onClick={(e) => saveAction(e)} >DONE</Button>
</Box>
}

</Card>
)
}
16 changes: 12 additions & 4 deletions src/containers/SessionDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ export default function SessionDetails({authUser, dataUser, session, exitSession
sessions: firebase.firestore.FieldValue.arrayUnion(session.id),
}).then(() => changeTab(e, 0))
}
const completeSession = () => {
const completeSession = (e) => {
setSessionInProgress(false)
sessionsRef.doc(session.id).update({
status: 'completed',
})
changeTab(e, 1)
// UPDATE Firestore (status, data fields)
console.log("startSession clicked")
}
Expand Down Expand Up @@ -80,7 +84,7 @@ export default function SessionDetails({authUser, dataUser, session, exitSession

<Box className={classes.sessionButtons}>
{session.status === "draft" && <Button className={classes.buttonPrimary} onClick={(e) => publishSession(e)}>Publish Session</Button>}
<Button className={classes.buttonPrimary} onClick={() => startSession()}>Start Session</Button>
{ dataUser.userType === "coach" && <Button className={classes.buttonPrimary} onClick={() => startSession()}>Start Session</Button>}
</Box>

<Box className={classes.sessionButtons}>
Expand All @@ -102,12 +106,16 @@ export default function SessionDetails({authUser, dataUser, session, exitSession

{ addingAction && <NewActionForm action={actions[actions.length-1]} sessionId={session.id} authUser={authUser} dataUser={dataUser} toggleAddAction={toggleAddAction} />}

<Box className={classes.sessionActionsButtions}>
{
dataUser.userType === "coach" &&
<Box className={classes.sessionActionsButtions}>
{ session.status &&
<Button className={classes.buttonPrimary} onClick={() => toggleAddAction()}>{addingAction ? 'Cancel Add Set' : 'Add Set'}</Button>
}
<Button className={classes.buttonPrimary} onClick={() => completeSession()}>COMPLETE SESSION</Button>
<Button className={classes.buttonPrimary} onClick={(e) => completeSession(e)}>COMPLETE SESSION</Button>
</Box>
}


</Paper>
)
Expand Down
6 changes: 5 additions & 1 deletion src/pages/DashPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ export default function DashPage({authUser, dataUser}) {
>
<Tab className={classes.tab} label="Upcoming" />
<Tab className={classes.tab} label="Completed" />
<Tab className={classes.tab} label="Drafts" />
{
dataUser?.userType === 'coach' &&
<Tab className={classes.tab} label="Drafts" />
}

{
dataUser?.userType === 'coach' &&
<Tab className={classes.tab} label="Create Session" />
Expand Down
1 change: 0 additions & 1 deletion src/styles/sessionStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ const newSessionFormStyles = makeStyles(() => ({
borderRadius: '15px',
backgroundColor: holisticTheme.bgBtnPrimary,
},

}))

const sessionActionStyles = makeStyles(() => ({
Expand Down

0 comments on commit cf9d2ba

Please sign in to comment.