From 29182cb6dd33dab1d85f655b51978960d8a85d69 Mon Sep 17 00:00:00 2001 From: Steffen Date: Mon, 6 May 2024 16:58:58 +0200 Subject: [PATCH] chore(avs): switch company (WIP) --- src/Handler/Admin/Avs.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Handler/Admin/Avs.hs b/src/Handler/Admin/Avs.hs index fa1ca7837..5ac754d06 100644 --- a/src/Handler/Admin/Avs.hs +++ b/src/Handler/Admin/Avs.hs @@ -747,20 +747,20 @@ postAdminAvsUserR uuid = do -- return fwgt -- TODO: make it optional, if there are eligible companies only - switchCompForm :: Handler Widget - switchCompForm = do + switchCompForm :: Maybe Company -> Handler Widget + switchCompForm mbPrime = do let switchAllCompForm :: AForm (HandlerFor UniWorX) (CryptoUUIDUser,CompanyName) switchAllCompForm = (,) <$> areq hiddenField "user-id" (Just uuid) - <*> areq (selectFieldList [(ciOriginal c, c) | c <- compsUsed]) "new primary company" Nothing - <* aopt (buttonField UserAvsSwitchCompany) "" Nothing + <*> areq (selectFieldList [(ciOriginal c, c) | c <- compsUsed]) "new primary company" (companyName <$> mbPrime) + -- <* aopt (buttonField UserAvsSwitchCompany) "" Nothing ((spRes, spWgt), spEnc) <- runFormPost . identifyForm ("switch-primary-company"::Text) $ renderAForm FormStandard switchAllCompForm formResultModal spRes (AdminAvsUserR uuid) (\(_,c) -> do lift $ $logInfoS "AVS" ("Switch company option result " <> tshow spRes) tell . pure $ Message Success [shamlet|TODO #{c} received|] Nothing ) return $ wrapForm spWgt - def { formAction = Just $ SomeRoute (AdminAvsUserR uuid), formEncoding = spEnc, formSubmit = FormNoSubmit, formAttrs = [ asyncSubmitAttr | isModal ]} + def { formAction = Just $ SomeRoute (AdminAvsUserR uuid), formEncoding = spEnc, formSubmit = FormSubmit, formAttrs = [ asyncSubmitAttr | isModal ]} compDict <- if 1 >= length compsUsed then return mempty -- switch company only sensible if there is more than one company to choose @@ -772,7 +772,7 @@ postAdminAvsUserR uuid = do comps :: [Entity Company] <- selectList fltrCmps [Asc CompanyName, Asc CompanyAvsId] -- company name is already unique, but AVS sometimes contains uses whitespace return (companyName <$> mbPrimeComp, Map.fromAscList [(cname,cid) | (Entity{entityKey=cid, entityVal=Company{companyName=cname}}) <- comps]) -- formDict <- Map.traverseWithKey runSwitchFrom compDict - swForm <- switchCompForm + swForm <- switchCompForm mbPrimeComp return (primName, --formDict, swForm)