chore(avs): switch company (WIP)

This commit is contained in:
Steffen Jost 2024-05-06 16:58:58 +02:00
parent 6084f92ad7
commit 29182cb6dd

View File

@ -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)