fix(schedule): use should-be-displayed result for tutorial actions

This commit is contained in:
Sarah Vaupel 2020-11-10 20:51:25 +01:00
parent 601cb3179f
commit 3919152ede

View File

@ -213,20 +213,14 @@ getCShowR tid ssh csh = do
| isRegistered -> return [whamlet|_{MsgTutorialRegistered}|]
| otherwise -> return mempty
tutScheduleOptSet <- if
| Just (uid,User{..}) <- mbAuth -> do
mTutorialScheduleOpt <- getBy $ UniqueTutorialScheduleOpt tutId uid
let
currentOpt = maybe
( maybe
(isRegistered && userScheduleOccurrenceDisplayDefault)
((&&) isRegistered . courseScheduleOptOpt . entityVal)
mCourseScheduleOpt
)
(tutorialScheduleOptOpt . entityVal)
mTutorialScheduleOpt
(tutScheduleForm, tutScheduleEnctype) <- liftHandler . generateFormPost . buttonForm' $ bool [BtnScheduleOptIn] [BtnScheduleOptOut] currentOpt
| Just (uid,_) <- mbAuth -> do
shouldBeDisplayedInSchedule <- E.selectExists . E.from $ \(c `E.InnerJoin` tut) -> do
E.on $ c E.^. CourseId E.==. tut E.^. TutorialCourse
E.where_ $ tut E.^. TutorialId E.==. E.val tutId
E.&&. tutorialShouldBeDisplayedInSchedule (Just uid) ata c tut
(tutScheduleForm, tutScheduleEnctype) <- liftHandler . generateFormPost . buttonForm' $ bool [BtnScheduleOptIn] [BtnScheduleOptOut] shouldBeDisplayedInSchedule
return $ wrapForm tutScheduleForm def
{ formAction = Just . SomeRoute $ CTutorialR tid ssh csh tutorialName (TScheduleOptSetR $ not currentOpt)
{ formAction = Just . SomeRoute $ CTutorialR tid ssh csh tutorialName (TScheduleOptSetR $ not shouldBeDisplayedInSchedule)
, formEncoding = tutScheduleEnctype
, formSubmit = FormNoSubmit
}