From 7aa3cb3453b1781be366d6e3ed6d49212d15e5d0 Mon Sep 17 00:00:00 2001 From: Yussif Mohammed Date: Sun, 30 Nov 2025 12:25:56 +0000 Subject: [PATCH 01/56] towards supporting teams in projects. --- src/Models/Projects/ProjectMembers.hs | 115 +++- src/Pages/BodyWrapper.hs | 11 +- src/Pages/Bots/Discord.hs | 43 +- src/Pages/Bots/Slack.hs | 56 +- src/Pages/Projects.hs | 414 ++++++++++++- src/Web/Routes.hs | 6 + static/migrations/0017_teams_table.sql | 20 + static/public/assets/css/tailwind.css | 10 +- .../assets/css/thirdparty/tagify.min.css | 571 ++++++++++++++++++ 9 files changed, 1219 insertions(+), 27 deletions(-) create mode 100644 static/migrations/0017_teams_table.sql create mode 100644 static/public/assets/css/thirdparty/tagify.min.css diff --git a/src/Models/Projects/ProjectMembers.hs b/src/Models/Projects/ProjectMembers.hs index 05a499b0f..5ba332870 100644 --- a/src/Models/Projects/ProjectMembers.hs +++ b/src/Models/Projects/ProjectMembers.hs @@ -7,9 +7,16 @@ module Models.Projects.ProjectMembers ( selectActiveProjectMembers, updateProjectMembersPermissons, softDeleteProjectMembers, + createTeam, + updateTeam, + getTeams, + getTeamByHandle, + TeamVM (..), + Team (..), ) where import Control.Error (note) +import Data.Aeson qualified as AE import Data.CaseInsensitive (CI) import Data.Default.Instances () import Data.Time (ZonedTime) @@ -25,10 +32,11 @@ import Database.PostgreSQL.Entity.Types ( Schema, TableName, ) -import Database.PostgreSQL.Simple (FromRow, Only (Only), ResultError (..), ToRow) +import Database.PostgreSQL.Simple (FromRow, In, Only (Only), ResultError (..), ToRow) import Database.PostgreSQL.Simple.FromField (FromField, fromField, returnError) import Database.PostgreSQL.Simple.SqlQQ (sql) import Database.PostgreSQL.Simple.ToField (Action (Escape), ToField, toField) +import Database.PostgreSQL.Simple.TypeInfo.Static (uuid) import Database.PostgreSQL.Transact (DBT, execute, executeMany) import Database.PostgreSQL.Transact qualified as PgT import Models.Projects.Projects qualified as Projects @@ -114,6 +122,8 @@ data ProjectMemberVM = ProjectMemberVM , userId :: Users.UserId , permission :: Permissions , email :: CI Text + , first_name :: Text + , last_name :: Text } deriving stock (Eq, Generic, Show) deriving anyclass (FromRow, NFData) @@ -123,7 +133,7 @@ selectActiveProjectMembers :: Projects.ProjectId -> DBT IO (V.Vector ProjectMemb selectActiveProjectMembers = query q where q = - [sql| SELECT pm.id, pm.user_id, pm.permission,us.email from projects.project_members pm + [sql| SELECT pm.id, pm.user_id, pm.permission,us.email, us.first_name, us.last_name from projects.project_members pm JOIN users.users us ON (pm.user_id=us.id) WHERE pm.project_id=?::uuid and pm.active=TRUE ORDER BY pm.created_at ASC; @@ -148,3 +158,104 @@ softDeleteProjectMembers vals = void $ execute q (Only (V.fromList vals)) [sql| UPDATE projects.project_members SET active = FALSE WHERE id = Any(?::uuid[]); |] + + +createTeam :: Projects.ProjectId -> Text -> Text -> Text -> V.Vector Users.UserId -> V.Vector Text -> V.Vector Text -> V.Vector Text -> DBT IO Int64 +createTeam pid name description handle memberIds notifEmails slackChannels discordChannels = do + execute q (pid, name, description, handle, memberIds, notifEmails, slackChannels, discordChannels) + where + q = + [sql| INSERT INTO projects.teams + (project_id, name, description, handle, members, notify_emails, slack_channels, discord_channels) + VALUES (?,?,?,?,?::uuid[],?,?,?) |] + + +updateTeam :: Projects.ProjectId -> UUID.UUID -> Text -> Text -> Text -> V.Vector Users.UserId -> V.Vector Text -> V.Vector Text -> V.Vector Text -> DBT IO Int64 +updateTeam pid tid name description handle memberIds notifEmails slackChannels discordChannels = do + execute q (name, description, handle, memberIds, notifEmails, slackChannels, discordChannels, pid, tid) + where + q = + [sql| UPDATE projects.teams + SET name = ?, description = ?, handle = ?, members = ?::uuid[], notify_emails = ?, slack_channels = ?, discord_channels = ? + WHERE project_id = ? AND id = ? |] + + +data Team = Team + { id :: UUID.UUID + , name :: Text + , description :: Text + , handle :: Text + , members :: V.Vector Users.UserId + , notify_emails :: V.Vector Text + , slack_channels :: V.Vector Text + , discord_channels :: V.Vector Text + } + deriving stock (Eq, Generic, Show) + deriving anyclass (FromRow, NFData) + + +getTeams :: Projects.ProjectId -> DBT IO (V.Vector Team) +getTeams pid = query q (Only pid) + where + q = + [sql| SELECT id, name, description, handle, members, notify_emails, slack_channels, discord_channels + FROM projects.teams + WHERE project_id = ? |] + + +data TeamVM = TeamVM + { id :: UUID.UUID + , name :: Text + , handle :: Text + , description :: Text + , notify_emails :: V.Vector Text + , slack_channels :: V.Vector Text + , discord_channels :: V.Vector Text + , members :: V.Vector TeamMemberVM + } + deriving stock (Eq, Generic, Show) + deriving anyclass (FromRow, NFData) + + +data TeamMemberVM = TeamMemberVM + { memberId :: UUID.UUID + , memberEmail :: CI Text + , memberName :: Text + , memberAvatar :: Maybe Text + } + deriving stock (Eq, Generic, Show) + deriving anyclass (FromField, NFData) + + +getTeamByHandle :: Projects.ProjectId -> Text -> DBT IO (V.Vector TeamVM) +getTeamByHandle pid handle = query q (pid, handle) + where + q = + [sql| + SELECT + t.id, + t.name, + t.handle, + t.description, + t.notify_emails, + t.slack_channels, + t.discord_channels, + COALESCE( + ( + SELECT jsonb_agg( + jsonb_build_object( + 'memberId', u.id, + 'memberName', u.first_name <> ' ' <> u.last_name, + 'memberEmail', u.email, + 'memberAvatar', u.avatar + ) + ) + FROM unnest(t.members) AS mid + JOIN users.users u ON u.id = mid + ), + '[]'::jsonb + ) AS members + FROM teams t + WHERE t.project_id = ? + AND t.handle = ? + |] diff --git a/src/Pages/BodyWrapper.hs b/src/Pages/BodyWrapper.hs index b44423ddd..4fc70e01f 100644 --- a/src/Pages/BodyWrapper.hs +++ b/src/Pages/BodyWrapper.hs @@ -92,7 +92,7 @@ bodyWrapper bcfg child = do meta_ [name_ "msapplication-TileColor", content_ "#da532c"] meta_ [name_ "theme-color", content_ "#ffffff"] link_ [rel_ "stylesheet", type_ "text/css", href_ $(hashAssetFile "/public/assets/css/thirdparty/notyf3.min.css")] - link_ [rel_ "stylesheet", href_ "https://cdn.jsdelivr.net/npm/@yaireo/tagify/dist/tagify.css", type_ "text/css"] + link_ [rel_ "stylesheet", href_ "/public/assets/css/thirdparty/tagify.min.css", type_ "text/css"] link_ [rel_ "stylesheet", href_ $(hashAssetFile "/public/assets/deps/gridstack/gridstack.min.css")] link_ [rel_ "stylesheet", href_ $(hashAssetFile "/public/assets/css/thirdparty/rrweb.css")] @@ -123,7 +123,7 @@ bodyWrapper bcfg child = do -- script_ [src_ $(hashAssetFile "/public/assets/js/thirdparty/instantpage5_1_0.js"), type_ "module", defer_ "true"] ("" :: Text) script_ [src_ $(hashAssetFile "/public/assets/js/main.js")] ("" :: Text) - script_ [src_ "https://unpkg.com/@monoscopetech/browser@latest/dist/monoscope.min.js"] ("" :: Text) + -- script_ [src_ "https://unpkg.com/@monoscopetech/browser@latest/dist/monoscope.min.js"] ("" :: Text) script_ [type_ "module", src_ $(hashAssetFile "/public/assets/web-components/dist/js/index.js")] ("" :: Text) @@ -569,7 +569,7 @@ sideNav sess project pageTitle menuItem = aside_ [class_ "border-r bg-fillWeaker , href_ $ "/p/" <> project.id.toText <> "/settings" ] $ span_ [class_ "w-9 h-9 p-2 flex justify-center items-center rounded-full bg-fillBrand-weak text-textBrand leading-none "] (faSprite_ "gear" "regular" "h-3 w-3") - >> span_ [class_ "hidden group-has-[#sidenav-toggle:checked]/pg:block"] "Settings" + >> span_ [class_ "hidden group-has-[#sidenav-toggle:checked]/pg:block"] "Settings" a_ [ class_ "hover:bg-fillBrand-weak " , target_ "blank" @@ -578,7 +578,7 @@ sideNav sess project pageTitle menuItem = aside_ [class_ "border-r bg-fillWeaker , href_ "https://apitoolkit.io/docs/" ] $ span_ [class_ "w-9 h-9 p-2 flex justify-center items-center rounded-full bg-fillBrand-weak text-textBrand leading-none"] (faSprite_ "circle-question" "regular" "h-3 w-3") - >> span_ [class_ "hidden group-has-[#sidenav-toggle:checked]/pg:block"] "Documentation" + >> span_ [class_ "hidden group-has-[#sidenav-toggle:checked]/pg:block"] "Documentation" -- Dark mode toggle div_ @@ -618,7 +618,7 @@ sideNav sess project pageTitle menuItem = aside_ [class_ "border-r bg-fillWeaker , [__| on click js posthog.reset(); end |] ] $ span_ [class_ "w-9 h-9 p-2 flex justify-center items-center rounded-full bg-fillError-weak text-textError leading-none"] (faSprite_ "arrow-right-from-bracket" "regular" "h-3 w-3") - >> span_ [class_ "hidden group-has-[#sidenav-toggle:checked]/pg:block"] "Logout" + >> span_ [class_ "hidden group-has-[#sidenav-toggle:checked]/pg:block"] "Logout" -- mapM_ renderNavBottomItem $ navBottomList project.id.toText @@ -694,6 +694,7 @@ navBottomList pidTxt = [ ("gear", "bg-fillBrand-weak", "text-textBrand", "Project settings", "/p/" <> pidTxt <> "/settings", Nothing, Nothing, Nothing) , ("key", "bg-fillSuccess-weak", "text-textSuccess", "API keys", "/p/" <> pidTxt <> "/apis", Nothing, Nothing, Nothing) , ("user-plus", "bg-fillWarning-weak", "text-textWarning", "Manage members", "/p/" <> pidTxt <> "/manage_members", Nothing, Nothing, Nothing) + , ("users", "bg-fillInfo-weak", "text-textInfo", "Manage teams", "/p/" <> pidTxt <> "/manage_teams", Nothing, Nothing, Nothing) , ("dollar", "bg-fillWarning-weak", "text-textWarning", "Manage billing", "/p/" <> pidTxt <> "/manage_billing", Nothing, Nothing, Nothing) , ("arrows-turn-right", "bg-fillBrand-weak", "text-textBrand", "Integrations", "/p/" <> pidTxt <> "/integrations", Nothing, Nothing, Nothing) , ("bucket", "", "", "Your S3 bucket", "/p/" <> pidTxt <> "/byob_s3", Nothing, Nothing, Nothing) diff --git a/src/Pages/Bots/Discord.hs b/src/Pages/Bots/Discord.hs index 1a9719235..9c27f22b8 100644 --- a/src/Pages/Bots/Discord.hs +++ b/src/Pages/Bots/Discord.hs @@ -1,6 +1,6 @@ {-# LANGUAGE PackageImports #-} -module Pages.Bots.Discord (linkDiscordGetH, discordInteractionsH, DiscordInteraction) where +module Pages.Bots.Discord (linkDiscordGetH, discordInteractionsH, getDiscordChannels, DiscordChannel (..), DiscordInteraction) where import Data.Aeson qualified as AE import Data.ByteString qualified as BS @@ -176,17 +176,17 @@ instance AE.FromJSON InteractionData where Just 3 -> MessageComponentData <$> v - AE..: "component_type" + AE..: "component_type" <*> v - AE..: "custom_id" + AE..: "custom_id" <*> v - AE..: "values" + AE..: "values" _ -> CommandData <$> v - AE..: "name" + AE..: "name" <*> v - AE..:? "options" + AE..:? "options" data InteractionOption = InteractionOption @@ -197,6 +197,33 @@ data InteractionOption = InteractionOption deriving anyclass (AE.FromJSON) +data DiscordChannel = DiscordChannel + { channelId :: Text + , channelName :: Text + , channelType :: Int + } + deriving (Show) + + +instance AE.FromJSON DiscordChannel where + parseJSON = AE.withObject "DiscordChannel" $ \o -> + DiscordChannel + <$> o AE..: "id" + <*> o AE..: "name" + <*> o AE..: "type" + + +getDiscordChannels :: HTTP :> es => Text -> Text -> Eff es [DiscordChannel] +getDiscordChannels token guildId = do + let url = "https://discord.com/api/v10/guilds/" <> T.unpack guildId <> "/channels" + opts = defaults & header "Authorization" .~ ["Bot " <> encodeUtf8 token] + r <- getWith opts url + let body = r ^. responseBody + case AE.eitherDecode body of + Left err -> return [] + Right chs -> return chs + + discordInteractionsH :: BS.ByteString -> Maybe BS.ByteString -> Maybe BS.ByteString -> ATBaseCtx AE.Value discordInteractionsH rawBody signatureM timestampM = do authCtx <- Effectful.Reader.Static.ask @AuthContext @@ -378,8 +405,8 @@ threadsPrompt msgs question = prompt , "- the user query is the main one to answer, but earlier messages may contain important clarifications or parameters." , "\nPrevious thread messages in json:\n" ] - <> [msgJson] - <> ["\n\nUser query: " <> question] + <> [msgJson] + <> ["\n\nUser query: " <> question] prompt = systemPrompt <> threadPrompt diff --git a/src/Pages/Bots/Slack.hs b/src/Pages/Bots/Slack.hs index f0b5873d2..240d878c4 100644 --- a/src/Pages/Bots/Slack.hs +++ b/src/Pages/Bots/Slack.hs @@ -1,9 +1,10 @@ {-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} -module Pages.Bots.Slack (linkProjectGetH, slackActionsH, SlackEventPayload, slackEventsPostH, SlackActionForm, externalOptionsH, slackInteractionsH, SlackInteraction) where +module Pages.Bots.Slack (linkProjectGetH, slackActionsH, SlackEventPayload, slackEventsPostH, getSlackChannels, SlackChannelsResponse (..), SlackChannel (..), SlackActionForm, externalOptionsH, slackInteractionsH, SlackInteraction) where import BackgroundJobs qualified as BgJobs import Control.Lens ((.~), (^.)) +import Data.Aeson (withObject) import Data.Aeson qualified as AE import Data.Aeson.Key qualified as KEM import Data.Aeson.KeyMap qualified as KEMP @@ -524,17 +525,17 @@ instance AE.FromJSON SlackEventPayload where "event_callback" -> EventCallback <$> v - AE..: "token" + AE..: "token" <*> v - AE..: "team_id" + AE..: "team_id" <*> v - AE..: "api_app_id" + AE..: "api_app_id" <*> v - AE..: "event" + AE..: "event" <*> v - AE..: "event_id" + AE..: "event_id" <*> v - AE..: "event_time" + AE..: "event_time" other -> fail $ "Unsupported Slack event type: " ++ show other @@ -635,6 +636,43 @@ data SlackThreadedMessage = SlackThreadedMessage deriving (Generic, Show) +-- | Channel representation (you can extend this) +data SlackChannel = SlackChannel + { channelId :: Text + , channelName :: Text + } + deriving (Show) + + +instance AE.FromJSON SlackChannel where + parseJSON = withObject "SlackChannel" $ \o -> do + cid <- o AE..: "id" + name <- o AE..: "name" + pure $ SlackChannel cid name + + +data SlackChannelsResponse = SlackChannelsResponse + { ok :: Bool + , channels :: [SlackChannel] + } + deriving (Generic, Show) + deriving anyclass (AE.FromJSON) + + +-- | Internal helper to call Slack API +getSlackChannels :: HTTP :> es => Text -> Text -> Eff es (Maybe SlackChannelsResponse) +getSlackChannels token team_id = do + let url = "https://slack.com/api/conversations.list" + opts = + defaults & header "Authorization" .~ ["Bearer " <> encodeUtf8 token] & Wreq.param "team_id" .~ [team_id] + + r <- getWith opts url + let resBody = r ^. responseBody + case AE.eitherDecode resBody of + Right val -> return $ Just val + Left err -> return Nothing + + instance AE.FromJSON SlackThreadedMessage where parseJSON = AE.genericParseJSON AE.defaultOptions{AE.fieldLabelModifier = \f -> if f == "type_" then "type" else f} @@ -672,7 +710,7 @@ threadsPrompt msgs question = prompt , "- the user query is the main one to answer, but earlier messages may contain important clarifications or parameters." , "\nPrevious thread messages in json:\n" ] - <> [msgJson] - <> ["\n\nUser query: " <> question] + <> [msgJson] + <> ["\n\nUser query: " <> question] prompt = systemPrompt <> threadPrompt diff --git a/src/Pages/Projects.hs b/src/Pages/Projects.hs index f7862f28d..380eb2e45 100644 --- a/src/Pages/Projects.hs +++ b/src/Pages/Projects.hs @@ -19,6 +19,8 @@ module Pages.Projects ( ManageMembersForm (..), manageSubGetH, ManageMembers (..), + -- ManageTeams + manageTeamsGetH, -- CreateProject createProjectPostH, createProjectFormV, @@ -33,6 +35,9 @@ module Pages.Projects ( CreateProject (..), pricingUpdateGetH, CreateProjectResp (..), + manageTeamPostH, + TeamForm (..), + teamGetH, ) where @@ -43,6 +48,7 @@ import Data.Base64.Types qualified as B64 import Data.CaseInsensitive (original) import Data.CaseInsensitive qualified as CI import Data.Default (Default (..)) +import Data.Effectful.UUID (UUID) import Data.Effectful.UUID qualified as UUID import Data.Effectful.Wreq import Data.Effectful.Wreq qualified as W @@ -61,10 +67,14 @@ import Effectful.Reader.Static (ask) import Fmt import GHC.Records (HasField (getField)) import Lucid +import Lucid (div_) import Lucid.Htmx +import Lucid.Htmx (hxPost_) import Lucid.Hyperscript (__) import Models.Apis.Slack (SlackData, getDiscordDataByProjectId, getProjectSlackData) +import Models.Apis.Slack qualified as Slack import Models.Projects.ProjectApiKeys qualified as ProjectApiKeys +import Models.Projects.ProjectMembers (TeamVM (..)) import Models.Projects.ProjectMembers qualified as ProjectMembers import Models.Projects.Projects qualified as Projects import Models.Users.Sessions qualified as Sessions @@ -73,6 +83,9 @@ import NeatInterpolation (text) import Network.Wreq (getWith) import OddJobs.Job (createJob) import Pages.BodyWrapper (BWConfig (..), PageCtx (..), bodyWrapper) +import Pages.Bots.Discord qualified as Discord +import Pages.Bots.Slack (channels, getSlackChannels) +import Pages.Bots.Slack qualified as SlackP import Pages.Components (paymentPlanPicker) import Pkg.Components.Widget (Widget (..), WidgetType (..), widget_) import Pkg.ConvertKit qualified as ConvertKit @@ -456,12 +469,12 @@ manageMembersPostH pid onboardingM form = do unless (null uAndPOldAndChanged) $ void - . dbtToEff + . dbtToEff $ ProjectMembers.updateProjectMembersPermissons uAndPOldAndChanged unless (null deletedUAndP) $ void - . dbtToEff + . dbtToEff $ ProjectMembers.softDeleteProjectMembers deletedUAndP projMembersLatest <- dbtToEff $ ProjectMembers.selectActiveProjectMembers pid @@ -477,6 +490,153 @@ manageMembersPostH pid onboardingM form = do addRespHeaders $ ManageMembersPost projMembers +data TeamForm = TeamForm + { teamName :: Text + , teamDescription :: Text + , teamHandle :: Text + , teamMembers :: V.Vector Users.UserId + , notifEmails :: V.Vector Text + , slackChannels :: V.Vector Text + , discordChannels :: V.Vector Text + , teamId :: Maybe UUID.UUID + } + deriving stock (Eq, Generic, Show) + deriving anyclass (FromForm) +instance AE.FromJSON TeamForm where + parseJSON = AE.withObject "TeamForm" $ \o -> do + TeamForm + <$> o AE..: "teamName" + <*> o AE..: "teamDescription" + <*> o AE..: "teamHandle" + <*> o AE..:? "teamMembers" AE..!= V.empty + <*> o AE..:? "notifEmails" AE..!= V.empty + <*> o AE..:? "slackChannels" AE..!= V.empty + <*> o AE..:? "discordChannels" AE..!= V.empty + <*> o AE..:? "teamId" + + +manageTeamPostH :: Projects.ProjectId -> TeamForm -> ATAuthCtx (RespHeaders (Html ())) +manageTeamPostH pid TeamForm{teamName, teamDescription, teamHandle, teamMembers, notifEmails, slackChannels, discordChannels, teamId} = do + rs <- case teamId of + Just tid -> do + _ <- dbtToEff $ ProjectMembers.updateTeam pid tid teamName teamDescription teamHandle teamMembers notifEmails slackChannels discordChannels + addSuccessToast "Team updated successfully" Nothing + html <- manageTeamsGetH pid (Just "from_post") + return html + Nothing -> do + _ <- dbtToEff $ ProjectMembers.createTeam pid teamName teamDescription teamHandle teamMembers notifEmails slackChannels discordChannels + addSuccessToast "Team saved successfully" Nothing + html <- manageTeamsGetH pid (Just "from_post") + return html + return rs + + +manageTeamsGetH :: Projects.ProjectId -> Maybe Text -> ATAuthCtx (RespHeaders (Html ())) +manageTeamsGetH pid layoutM = do + (sess, project) <- Sessions.sessionAndProject pid + appCtx <- ask @AuthContext + projMembers <- dbtToEff $ ProjectMembers.selectActiveProjectMembers pid + slackDataM <- Slack.getProjectSlackData pid + channels <- case slackDataM of + Just slackData -> do + channels' <- SlackP.getSlackChannels appCtx.env.slackBotToken slackData.teamId + case channels' of + Just chs -> return chs.channels + Nothing -> return [] + Nothing -> return [] + + discordDataM <- Slack.getDiscordDataByProjectId pid + discordChannels <- case discordDataM of + Just discordData -> do + channels' <- Discord.getDiscordChannels appCtx.env.discordBotToken discordData.guildId + return channels' + Nothing -> return [] + teams <- dbtToEff $ ProjectMembers.getTeams pid + let bwconf = + (def :: BWConfig) + { sessM = Just sess + , pageTitle = "Manage teams" + , currProject = Just project + , isSettingsPage = True + , config = appCtx.config + } + case layoutM of + Just _ -> do + addRespHeaders $ manageTeamsPage pid projMembers channels discordChannels teams + _ -> do + addRespHeaders $ bodyWrapper bwconf $ manageTeamsPage pid projMembers channels discordChannels teams + + +manageTeamsPage :: Projects.ProjectId -> V.Vector ProjectMembers.ProjectMemberVM -> [SlackP.SlackChannel] -> [Discord.DiscordChannel] -> V.Vector ProjectMembers.Team -> Html () +manageTeamsPage pid projMembers channels discordChannels teams = do + let whiteList = decodeUtf8 $ AE.encode $ (\x -> AE.object ["name" AE..= (x.first_name <> " " <> x.last_name), "email" AE..= x.email, "value" AE..= x.id]) <$> projMembers + let channelWhiteList = decodeUtf8 $ AE.encode $ (\x -> AE.object ["name" AE..= ("#" <> x.channelName), "value" AE..= x.channelId]) <$> channels + let discordWhiteList = decodeUtf8 $ AE.encode $ (\x -> AE.object ["name" AE..= ("#" <> x.channelName), "value" AE..= x.channelId]) <$> discordChannels + section_ [id_ "main-content", class_ "w-full py-8"] do + div_ [class_ "p-6"] do + div_ [class_ "mb-8 w-full flex items-center justify-between"] do + div_ [class_ "flex flex-col gap-2"] do + h2_ [class_ "text-textStrong text-3xl font-semibold"] "Teams" + p_ [class_ "text-textWeak text-sm"] "Manage your project teams and their access" + label_ [class_ "btn btn-primary btn-sm", Lucid.for_ "n-new-team-modal"] (faSprite_ "plus" "regular" "h-4 w-4 mr-2" >> "New Team") + input_ [type_ "checkbox", id_ "n-new-team-modal", class_ "modal-toggle"] + teamModal pid Nothing whiteList channelWhiteList discordWhiteList + div_ [class_ "flex items-center gap-4"] do + label_ [class_ "input w-96"] do + faSprite_ "magnifying-glass" "regular" "h-4 w-4 text-textWeak" + input_ [type_ "text", placeholder_ "Search teams...", class_ ""] + span_ [class_ "text-textWeak text-sm"] $ (show (V.length teams) <> " teams found") + div_ [class_ "mt-6 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6"] $ mapM_ (\t -> teamCard pid t whiteList channelWhiteList discordWhiteList) (V.toList teams) + + +teamCard :: Projects.ProjectId -> ProjectMembers.Team -> Text -> Text -> Text -> Html () +teamCard pid team whiteList channelWhiteList discordWhiteList = do + a_ [href_ $ "/p/" <> pid.toText <> "/manage_teams/" <> team.handle, class_ "bg-base-100 border border-strokeWeak rounded-xl shadow-sm hover:shadow-md transition-shadow duration-200 overflow-hidden"] do + div_ [class_ "p-5 pb-3"] do + div_ [class_ "flex justify-between items-start mb-3"] do + div_ [class_ "flex-1 min-w-0"] do + h4_ [class_ "text-textStrong font-semibold text-lg"] $ toHtml team.name + p_ [class_ "text-textWeak text-sm mt-1 line-clamp-2"] $ toHtml team.description + label_ [class_ "btn btn-ghost btn-sm", Lucid.for_ (team.handle <> "-new-team-modal")] "Edit" + input_ [type_ "checkbox", id_ (team.handle <> "-new-team-modal"), class_ "modal-toggle"] + teamModal pid (Just team) whiteList channelWhiteList discordWhiteList + div_ [class_ "flex items-center justify-between text-sm text-textWeak"] do + div_ [class_ "flex items-center gap-2"] do + faSprite_ "users" "regular" "h-3.5 w-3.5" + span_ [] $ toHtml $ (show $ V.length team.members) <> " members" + div_ [class_ "flex items-center gap-2"] do + when (not $ V.null team.slack_channels) do + faSprite_ "slack" "regular" "h-3.5 w-3.5" + when (not $ V.null team.discord_channels) do + faSprite_ "discord" "regular" "h-3.5 w-3.5" + when (not $ V.null team.notify_emails) do + faSprite_ "envelope" "regular" "h-3.5 w-3.5" + + +teamGetH :: Projects.ProjectId -> Text -> ATAuthCtx (RespHeaders (Html ())) +teamGetH pid handle = do + (sess, project) <- Sessions.sessionAndProject pid + appCtx <- ask @AuthContext + teamVm <- dbtToEff $ ProjectMembers.getTeamByHandle pid handle + let bwconf = + (def :: BWConfig) + { sessM = Just sess + , pageTitle = "Manage teams" + , currProject = Just project + , isSettingsPage = True + , config = appCtx.config + } + addRespHeaders $ bodyWrapper bwconf $ teamPage pid + + +teamPage :: Projects.ProjectId -> Html () +teamPage pid = do + section_ [id_ "main-content", class_ "w-full py-16"] do + div_ [class_ "p-6 w-[606px] mx-auto"] do + h2_ [class_ "text-textStrong mb-4 text-xl font-semibold"] "Manage Team" + p_ [class_ "text-textWeak text-sm leading-tight"] "We'll email them instructions and a link to sign in" + + manageMembersGetH :: Projects.ProjectId -> ATAuthCtx (RespHeaders ManageMembers) manageMembersGetH pid = do (sess, project) <- Sessions.sessionAndProject pid @@ -1022,3 +1182,253 @@ alertConfiguration newEndpointsAlerts errorAlerts weeklyReportsAlerts dailyRepor switchRow "Receive weekly reports alerts" "weeklyNotifs" "Get a summary of your project activity every week" weeklyReportsAlerts hr_ [class_ "border-border my-2"] switchRow "Receive daily reports alerts" "dailyNotifs" "Receive daily summaries of your project metrics" dailyReportsAlerts + + +-- Types +data TeamMember = TeamMember + { memberId :: Text + , memberEmail :: Text + , memberName :: Text + , memberRole :: Role + } + + +data Role = Owner | Admin | Member | Viewer + deriving (Eq, Show) + + +data NotificationChannel + = EmailChannel Text + | SlackChannel Text Text -- url, name + | DiscordChannel Text Text + | WhatsAppChannel Text + + +-- Main Modal Component +teamModal :: Projects.ProjectId -> Maybe ProjectMembers.Team -> Text -> Text -> Text -> Html () +teamModal pid team whiteList channelWhiteList discordWhiteList = do + let name = maybe "" (.name) team + let handle = maybe "" (.handle) team + let description = maybe "" (.description) team + let teamId = fmap (.id) team + let prefix = maybe "n" (\x -> x.handle) team + let membersTags = decodeUtf8 $ AE.encode $ maybe [] (\t -> ((.toText) <$> t.members)) team + let notifEmails = decodeUtf8 $ AE.encode $ maybe [] (.notify_emails) team + let slackChannels = decodeUtf8 $ AE.encode $ maybe [] (.slack_channels) team + let discordChannels = decodeUtf8 $ AE.encode $ maybe [] (.discord_channels) team + + div_ [class_ "modal", role_ "dialog", style_ "--color-base-100: var(--color-bgOverlay)"] $ do + div_ [class_ "modal-box"] $ do + form_ + [ hxPost_ "" + , hxExt_ "json-enc" + , hxVals_ [text|js:{...getTagValues(`$prefix`)}|] + , hxTarget_ "#main-content" + , hxSwap_ "outerHTML" + ] + do + div_ [class_ "px-2 max-h-[75vh] overflow-y-auto"] $ do + whenJust teamId $ \tid -> do + input_ + [ type_ "hidden" + , id_ $ prefix <> "-team-id" + , name_ "teamId" + , value_ $ UUID.toText tid + ] + div_ [class_ "sticky top-0 pb-2 bg-[var(--color-bgOverlay)] border-b border-border z-50"] $ do + h2_ [class_ "text-lg font-semibold flex items-center gap-2"] do + faSprite_ "users" "solid" "w-4 h-4 " + toHtml $ if isJust team then "Edit Team " <> name else "Create Team" + p_ [class_ "text-sm text-textWeak"] + $ "Manage team details, members, and notification channels" + div_ [class_ "flex-1 overflow-y-auto space-y-8 mt-4"] $ do + teamDetailsSection name handle description + div_ [class_ "pb-2 space-y-4"] $ do + h3_ [class_ "text-sm font-medium flex items-center gap-2 pb-2 border-b border-strokeWeak"] $ do + "Add Members" + div_ [class_ "flex gap-2"] $ do + textarea_ + [ class_ "min-h-10 w-full rounded border-strokeWeak input resize-none" + , type_ "email" + , placeholder_ "Add members" + , id_ $ prefix <> "-team-members-input" + , name_ "teamMembers" + , style_ "border: 1px solid var(--color-strokeWeak)" + ] + pass + notificationChannelsSection prefix + div_ [class_ "modal-action"] $ do + label_ [Lucid.for_ (prefix <> "-new-team-modal"), class_ "btn btn-sm btn-outline", type_ "button"] + $ "Cancel" + button_ [class_ "btn btn-sm btn-primary ml-4", type_ "submit"] + $ "Save Team" + label_ [class_ "modal-backdrop", Lucid.for_ (prefix <> "-new-team-modal")] "Close" + script_ + [text| + // Factory function for creating Tagify instances +function createTagify(selector, options = {}) { + const defaultOptions = { + skipInvalid: true, + editTags: {clicks: 2, keepInvalid: false}, + dropdown: { enabled: 1,fuzzySearch: true, position: 'text', caseSensitive: false} + }; + return new Tagify(document.querySelector(selector), { ...defaultOptions, ...options }); +} + +var customTagTemplate = { + tag: function(tagData) { + return ` + +
+ ${tagData.name} +
+
`; + }, + dropdownItemNoMatch: (data) => `No suggestion found for: ${data.value}` +}; + +var dropdown = {mapValueTo: 'name', searchKeys: ['name', 'value']} + +function getTagValues(prefix) { + return { + teamMembers: window[`$${prefix}-membersTagify`].value.map(item => item.value), + notifEmails: window[`$${prefix}-notifEmailsTagify`].value.map(item => item.value), + slackChannels: window[`$${prefix}-slackTagify`].value.map(item => item.value), + discordChannels: window[`$${prefix}-discordTagify`].value.map(item => item.value) + } +} + +// Initialize all Tagify instances +window[`$prefix-membersTagify`] = createTagify('#$prefix-team-members-input', { + enforceWhitelist: true, + whitelist: $whiteList, + placeholder: "Add member", + dropdown, + templates: customTagTemplate +}); + +var existingMembers = $membersTags +var memberTags = [] +existingMembers.forEach(member => { + const target = $whiteList.find(v => v.value == member) + if(target) { + memberTags.push(target) + } +}) +window[`$prefix-membersTagify`].addTags(memberTags) + +window[`$prefix-notifEmailsTagify`] = createTagify('#$prefix-notif-emails-input', { placeholder: "Add email"}); +window[`$prefix-notifEmailsTagify`].addTags($notifEmails) + + + +window[`$prefix-slackTagify`] = createTagify('#$prefix-slack-channels-input', { + enforceWhitelist: true, + whitelist: $channelWhiteList, + placeholder: "Add Slack channel", + dropdown, + templates: customTagTemplate +}); + +var slackChannels = $slackChannels +var channels = [] +slackChannels.forEach(channel => { + const target = $channelWhiteList.find(v => v.value == channel) + if(target) { + channels.push(target) + } +}) +window[`$prefix-slackTagify`].addTags(channels) + +window[`$prefix-discordTagify`] = createTagify('#$prefix-discord-channels-input', { + enforceWhitelist: true, + whitelist: $discordWhiteList, + placeholder: "Add Discord channel", + dropdown, + templates: customTagTemplate +}); + +var discordChannels = $discordChannels +var discordChannelTags = [] +discordChannels.forEach(channel => { + const target = $discordWhiteList.find(v => v.value === channel) + if(target) { + discordChannelTags.push(target) + } +}) +window[`$prefix-discordTagify`].addTags(discordChannelTags) +// Update email whitelist when members change +window[`$prefix-membersTagify`].on("change", (e) => { + window[`$prefix-notifEmailsTagify`].settings.whitelist = window[`$prefix-membersTagify`].value.map(item => item.email); +}); + |] + + +-- Team Details Section +teamDetailsSection :: Text -> Text -> Text -> Html () +teamDetailsSection name handle description = do + div_ [class_ "space-y-4"] $ do + -- Team Name Field + div_ [class_ "flex items-center w-full gap-2 justify-between"] do + div_ [class_ "flex flex-col w-full gap-2"] $ do + label_ [class_ "text-sm font-medium ", Lucid.for_ "team-name"] "Team Name" + input_ + [ class_ "input w-full" + , type_ "text" + , id_ "team-name" + , name_ "teamName" + , placeholder_ "e.g. Backend Team" + , value_ name + ] + + div_ [class_ "flex flex-col gap-2 w-full"] $ do + label_ [class_ "text-sm font-medium ", Lucid.for_ "team-handle"] "Team Handle" + input_ + [ class_ "input w-full" + , type_ "text" + , id_ "team-handle" + , name_ "teamHandle" + , placeholder_ "e.g. backend-team" + , value_ handle + ] + -- Description Field + div_ [class_ "flex flex-col gap-2"] $ do + label_ [class_ "text-sm font-medium ", Lucid.for_ "team-description"] "Description" + textarea_ + [ class_ "w-full p-2 min-h-[80px] input focus:outline-none focus:ring-2 focus:ring-ring resize-none" + , id_ "team-description" + , name_ "teamDescription" + , placeholder_ "What does this team do?" + ] + $ toHtml description + + +-- Notification Channels Section +notificationChannelsSection :: Text -> Html () +notificationChannelsSection prefix = do + div_ [class_ "space-y-4"] $ do + h3_ [class_ "text-sm font-medium flex items-center gap-2 pb-2 border-b border-strokeWeak"] "Notification Channels" + div_ [class_ "w-full space-y-8"] $ do + channelBlock "Email addresses" (prefix <> "-notif-emails-input") "Add email addresses" "notifEmails" "envelope" + channelBlock "Slack Channels" (prefix <> "-slack-channels-input") "Add slack channels" "slackChannels" "slack" + channelBlock "Discord Channels" (prefix <> "-discord-channels-input") "Add channels" "discordChannels" "discord" + channelBlock "WhatsApp Numbers" (prefix <> "-notif-whatsapp-numbers-input") "Add numbers" "notifWhatsAppNumbers" "whatsapp" + + +-- Reusable helper +channelBlock :: Text -> Text -> Text -> Text -> Text -> Html () +channelBlock title inputId placeholder name icon = div_ [class_ "flex flex-col gap-2"] do + label_ [class_ "text-sm font-medium flex items-center gap-2", Lucid.for_ inputId] do + faSprite_ icon "solid" "w-4 h-4" + toHtml title + textarea_ + [ class_ "input w-full min-h-10 resize-none rounded" + , id_ inputId + , placeholder_ placeholder + ] + "" diff --git a/src/Web/Routes.hs b/src/Web/Routes.hs index c9f5f787e..723b3c0c8 100644 --- a/src/Web/Routes.hs +++ b/src/Web/Routes.hs @@ -306,6 +306,9 @@ data ProjectsRoutes' mode = ProjectsRoutes' , -- Member management membersManageGet :: mode :- "p" :> Capture "projectId" Projects.ProjectId :> "manage_members" :> Get '[HTML] (RespHeaders ManageMembers.ManageMembers) , membersManagePost :: mode :- "p" :> Capture "projectId" Projects.ProjectId :> "manage_members" :> QPT "onboarding" :> ReqBody '[FormUrlEncoded] ManageMembers.ManageMembersForm :> Post '[HTML] (RespHeaders ManageMembers.ManageMembers) + , teamsManageGet :: mode :- "p" :> Capture "projectId" Projects.ProjectId :> "manage_teams" :> QPT "what" :> Get '[HTML] (RespHeaders (Html ())) + , teamsManagePost :: mode :- "p" :> Capture "projectId" Projects.ProjectId :> "manage_teams" :> ReqBody '[JSON] ManageMembers.TeamForm :> Post '[HTML] (RespHeaders (Html ())) + , teamGet :: mode :- "p" :> Capture "projectId" Projects.ProjectId :> "manage_teams" :> Capture "teamHandle" Text :> Get '[HTML] (RespHeaders (Html ())) , manageSubscriptionGet :: mode :- "p" :> Capture "projectId" Projects.ProjectId :> "manage_subscription" :> Get '[HTML] (RespHeaders (Html ())) , -- Notifications notificationsUpdateChannelPost :: mode :- "p" :> Capture "projectId" Projects.ProjectId :> "notifications-channels" :> ReqBody '[FormUrlEncoded] Integrations.NotifListForm :> Post '[HTML] (RespHeaders Integrations.NotificationsUpdatePost) @@ -481,6 +484,9 @@ projectsServer = , deleteProjectGet = CreateProject.deleteProjectGetH , membersManageGet = ManageMembers.manageMembersGetH , membersManagePost = ManageMembers.manageMembersPostH + , teamsManageGet = ManageMembers.manageTeamsGetH + , teamsManagePost = ManageMembers.manageTeamPostH + , teamGet = ManageMembers.teamGetH , manageSubscriptionGet = ManageMembers.manageSubGetH , onboading = Onboarding.onboardingGetH , onboardingInfoPost = Onboarding.onboardingInfoPostH diff --git a/static/migrations/0017_teams_table.sql b/static/migrations/0017_teams_table.sql new file mode 100644 index 000000000..7af4b9098 --- /dev/null +++ b/static/migrations/0017_teams_table.sql @@ -0,0 +1,20 @@ +BEGIN; + +CREATE TABLE IF NOT EXISTS projects.teams ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + project_id UUID NOT NULL REFERENCES projects.projects(id) ON DELETE CASCADE, + name VARCHAR(255) NOT NULL, + handle VARCHAR(255) NOT NULL, + description TEXT, + members UUID[] DEFAULT '{}', + notify_emails TEXT[] DEFAULT '{}', + slack_channels TEXT[] DEFAULT '{}', + discord_channels TEXT[] DEFAULT '{}', + phone_numbers TEXT[] DEFAULT '{}', + created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(), + updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(), + UNIQUE(project_id, handle) +); + + +COMMIT; \ No newline at end of file diff --git a/static/public/assets/css/tailwind.css b/static/public/assets/css/tailwind.css index a013e1c6f..484bf3a69 100644 --- a/static/public/assets/css/tailwind.css +++ b/static/public/assets/css/tailwind.css @@ -291,6 +291,7 @@ body, :host { .dropdown summary { list-style: none; } + .dropdown summary::-webkit-details-marker { display: none; } @@ -646,6 +647,8 @@ code, pre, .code, .monospace { @apply bg-fillWeak text-textStrong border border-strokeWarning-strong; } +.tagify {} + @utility ctable { & :where(.table-pin-rows thead tr) { @apply sticky top-0 z-10 bg-bgBase; @@ -1109,7 +1112,12 @@ code, pre, .code, .monospace { } /****** Tagify *****/ -.dash-variable .tagify { + +.modal > tags { + @apply border-strokeWeak; + } + + .dash-variable .tagify { margin-top: -0.5rem; --tags-border-color: transparent; --tag-text-color: var(--color-textStrong); diff --git a/static/public/assets/css/thirdparty/tagify.min.css b/static/public/assets/css/thirdparty/tagify.min.css new file mode 100644 index 000000000..3f5cad62c --- /dev/null +++ b/static/public/assets/css/thirdparty/tagify.min.css @@ -0,0 +1,571 @@ +@charset "UTF-8"; +:root { + --tagify-dd-color-primary: rgb(53, 149, 246); + --tagify-dd-text-color: black; + --tagify-dd-bg-color: white; + --tagify-dd-item-pad: 0.3em 0.5em; + --tagify-dd-max-height: 300px; +} +.tagify { + --tags-disabled-bg: #f1f1f1; + --tags-border-color: var(--color-strokeWeak); + --tags-hover-border-color: #ccc; + --tags-focus-border-color: #3595f6; + --tag-border-radius: var(--radius-field); + --tag-bg: var(--color-fillWeak); + --tag-hover: var(--color-fillWeaker); + --tag-text-color: var(--color-textStrong); + --tag-text-color--edit: var(--color-textStrong); + --tag-pad: 0.3em 0.5em; + --tag-inset-shadow-size: 1.2em; + --tag-invalid-color: #d39494; + --tag-invalid-bg: rgba(211, 148, 148, 0.5); + --tag--min-width: 1ch; + --tag--max-width: 100%; + --tag-hide-transition: 0.3s; + --tag-remove-bg: rgba(211, 148, 148, 0.3); + --tag-remove-btn-color: black; + --tag-remove-btn-bg: none; + --tag-remove-btn-bg--hover: #c77777; + --input-color: inherit; + --placeholder-color: var(--color-textWeak); + --placeholder-color-focus: var(--color-textWeak); + --loader-size: 0.8em; + --readonly-striped: 1; + display: inline-flex; + align-items: flex-start; + align-content: baseline; + flex-wrap: wrap; + border: 1px solid var(--tags-border-color); + padding: 0; + line-height: 0; + outline: 0; + position: relative; + box-sizing: border-box; + transition: 0.1s; +} +@keyframes tags--bump { + 30% { + transform: scale(1.2); + } +} +@keyframes rotateLoader { + to { + transform: rotate(1turn); + } +} +.tagify:has([contenteditable='true']) { + cursor: text; +} +.tagify:hover:not(.tagify--focus):not(.tagify--invalid) { + --tags-border-color: var(--tags-hover-border-color); +} +.tagify[disabled] { + background: var(--tags-disabled-bg); + filter: saturate(0); + opacity: 0.5; + pointer-events: none; +} +.tagify[disabled].tagify--empty > .tagify__input::before { + position: relative; +} +.tagify[disabled].tagify--select, +.tagify[readonly].tagify--select { + pointer-events: none; +} +.tagify[disabled]:not(.tagify--mix):not(.tagify--select):not(.tagify--empty), +.tagify[readonly]:not(.tagify--mix):not(.tagify--select):not(.tagify--empty) { + cursor: default; +} +.tagify[disabled]:not(.tagify--mix):not(.tagify--select):not(.tagify--empty) > .tagify__input, +.tagify[readonly]:not(.tagify--mix):not(.tagify--select):not(.tagify--empty) > .tagify__input { + visibility: hidden; + width: 0; + margin: 5px 0; +} +.tagify[disabled]:not(.tagify--mix):not(.tagify--select):not(.tagify--empty) .tagify__tag > div, +.tagify[readonly]:not(.tagify--mix):not(.tagify--select):not(.tagify--empty) .tagify__tag > div { + padding: var(--tag-pad); +} +.tagify[disabled]:not(.tagify--mix):not(.tagify--select):not(.tagify--empty) .tagify__tag > div::before, +.tagify[readonly]:not(.tagify--mix):not(.tagify--select):not(.tagify--empty) .tagify__tag > div::before { + animation: readonlyStyles 1s calc(-1s * (var(--readonly-striped) - 1)) paused; +} +@keyframes readonlyStyles { + 0% { + background: linear-gradient(45deg, var(--tag-bg) 25%, transparent 25%, transparent 50%, var(--tag-bg) 50%, var(--tag-bg) 75%, transparent 75%, transparent) 0/5px 5px; + box-shadow: none; + filter: brightness(0.95); + } +} +.tagify[disabled] .tagify__tag__removeBtn, +.tagify[readonly] .tagify__tag__removeBtn { + display: none; +} +.tagify--loading .tagify__input > br:last-child { + display: none; +} +.tagify--loading .tagify__input::before { + content: none; +} +.tagify--loading .tagify__input::after { + content: ''; + vertical-align: middle; + opacity: 1; + width: 0.7em; + height: 0.7em; + width: var(--loader-size); + height: var(--loader-size); + min-width: 0; + border: 3px solid; + border-color: #eee #bbb #888 transparent; + border-radius: 50%; + animation: rotateLoader 0.4s infinite linear; + content: '' !important; + margin: -2px 0 -2px 0.5em; +} +.tagify--loading .tagify__input:empty::after { + margin-left: 0; +} +.tagify + input, +.tagify + textarea { + position: absolute !important; + left: -9999em !important; + transform: scale(0) !important; +} +.tagify__tag { + display: inline-flex; + align-items: center; + max-width: var(--tag--max-width); + margin-inline: 5px 0; + margin-block: 5px; + position: relative; + z-index: 1; + outline: 0; + line-height: normal; + cursor: default; + transition: 0.13s ease-out; +} +.tagify__tag > div { + display: flex; + flex: 1; + vertical-align: top; + box-sizing: border-box; + max-width: 100%; + padding: var(--tag-pad); + color: var(--tag-text-color); + line-height: inherit; + border-radius: var(--tag-border-radius); + white-space: nowrap; + transition: 0.13s ease-out; +} +.tagify__tag > div > * { + white-space: pre-wrap; + overflow: hidden; + text-overflow: ellipsis; + display: inline-block; + vertical-align: top; + min-width: var(--tag--min-width); + max-width: var(--tag--max-width); + transition: 0.8s ease, 0.1s color; +} +.tagify__tag > div > [contenteditable] { + display: block; + outline: 0; + -webkit-user-select: text; + user-select: text; + cursor: text; + margin: -2px; + padding: 2px; + max-width: 350px; +} +.tagify__tag > div > :only-child { + width: 100%; +} +.tagify__tag > div::before { + content: ''; + position: absolute; + border-radius: inherit; + inset: var(--tag-bg-inset, 0); + z-index: -1; + pointer-events: none; + transition: 120ms ease; + animation: tags--bump 0.3s ease-out 1; + box-shadow: 0 0 0 var(--tag-inset-shadow-size) var(--tag-bg) inset; +} +.tagify__tag:focus div::before, +.tagify__tag:hover:not([readonly]) div::before { + --tag-bg-inset: -2.5px; + --tag-bg: var(--tag-hover); +} +.tagify__tag--loading { + pointer-events: none; +} +.tagify__tag--loading .tagify__tag__removeBtn { + display: none; +} +.tagify__tag--loading::after { + --loader-size: 0.4em; + content: ''; + vertical-align: middle; + opacity: 1; + width: 0.7em; + height: 0.7em; + width: var(--loader-size); + height: var(--loader-size); + min-width: 0; + border: 3px solid; + border-color: #eee #bbb #888 transparent; + border-radius: 50%; + animation: rotateLoader 0.4s infinite linear; + margin: 0 0.5em 0 -0.1em; +} +.tagify__tag--flash div::before { + animation: none; +} +.tagify__tag--hide { + width: 0 !important; + padding-left: 0; + padding-right: 0; + margin-left: 0; + margin-right: 0; + opacity: 0; + transform: scale(0); + transition: var(--tag-hide-transition); + pointer-events: none; +} +.tagify__tag--hide > div > * { + white-space: nowrap; +} +.tagify__tag.tagify--noAnim > div::before { + animation: none; +} +.tagify__tag.tagify--notAllowed:not(.tagify__tag--editable) div > span { + opacity: 0.5; +} +.tagify__tag.tagify--notAllowed:not(.tagify__tag--editable) div::before { + --tag-bg: var(--tag-invalid-bg); + transition: 0.2s; +} +.tagify__tag[readonly] .tagify__tag__removeBtn { + display: none; +} +.tagify__tag[readonly] > div::before { + animation: readonlyStyles 1s calc(-1s * (var(--readonly-striped) - 1)) paused; +} +@keyframes readonlyStyles { + 0% { + background: linear-gradient(45deg, var(--tag-bg) 25%, transparent 25%, transparent 50%, var(--tag-bg) 50%, var(--tag-bg) 75%, transparent 75%, transparent) 0/5px 5px; + box-shadow: none; + filter: brightness(0.95); + } +} +.tagify__tag--editable > div { + color: var(--tag-text-color--edit); +} +.tagify__tag--editable > div::before { + box-shadow: 0 0 0 2px var(--tag-hover) inset !important; +} +.tagify__tag--editable > .tagify__tag__removeBtn { + pointer-events: none; + opacity: 0; + transform: translateX(100%) translateX(5px); +} +.tagify__tag--editable.tagify--invalid > div::before { + box-shadow: 0 0 0 2px var(--tag-invalid-color) inset !important; +} +.tagify__tag__removeBtn { + order: 5; + display: inline-flex; + align-items: center; + justify-content: center; + border-radius: 50px; + cursor: pointer; + font: 14px/1 Arial; + background: var(--tag-remove-btn-bg); + color: var(--tag-remove-btn-color); + width: 14px; + height: 14px; + margin-inline: auto 4.6666666667px; + overflow: hidden; + transition: 0.2s ease-out; +} +.tagify__tag__removeBtn::after { + content: '×'; + transition: 0.3s, color 0s; +} +.tagify__tag__removeBtn:hover { + color: #fff; + background: var(--tag-remove-btn-bg--hover); +} +.tagify__tag__removeBtn:hover + div > span { + opacity: 0.5; +} +.tagify__tag__removeBtn:hover + div::before { + box-shadow: 0 0 0 var(--tag-inset-shadow-size) var(--tag-remove-bg, rgba(211, 148, 148, 0.3)) inset !important; + transition: box-shadow 0.2s; +} +.tagify:not(.tagify--mix) .tagify__input br { + display: none; +} +.tagify:not(.tagify--mix) .tagify__input * { + display: inline; + white-space: nowrap; +} +.tagify__input { + flex-grow: 1; + display: inline-block; + margin: 5px; + padding: var(--tag-pad); + line-height: normal; + min-width: 110px; + min-height: 1.5lh; + position: relative; + white-space: pre-wrap; + color: var(--input-color); + box-sizing: inherit; + overflow: hidden; +} +.tagify__input:focus { + outline: 0; +} +.tagify__input:focus::before { + transition: 0.2s ease-out; + opacity: 0; + transform: translatex(6px); +} +@supports (-ms-ime-align: auto) { + .tagify__input:focus::before { + display: none; + } +} +.tagify__input:focus:empty::before { + transition: 0.2s ease-out; + opacity: 1; + transform: none; + color: rgba(0, 0, 0, 0.25); + color: var(--placeholder-color-focus); +} +@-moz-document url-prefix() { + .tagify__input:focus:empty::after { + display: none; + } +} +.tagify__input::before { + content: attr(data-placeholder); + width: 100%; + height: 100%; + margin: auto 0; + z-index: 1; + color: var(--placeholder-color); + white-space: nowrap; + text-overflow: ellipsis; + overflow: hidden; + pointer-events: none; + opacity: 0; + position: absolute; +} +.tagify__input::after { + content: attr(data-suggest); + display: inline-block; + vertical-align: middle; + position: absolute; + min-width: calc(100% - 1.5em); + text-overflow: ellipsis; + overflow: hidden; + white-space: pre; + color: var(--tag-text-color); + opacity: 0.3; + pointer-events: none; + max-width: 100px; +} +.tagify__input .tagify__tag { + margin: 0 1px; +} +.tagify--mix { + display: block; +} +.tagify--mix .tagify__input { + padding: 5px; + margin: 0; + width: 100%; + height: 100%; + line-height: 1.5; + display: block; +} +.tagify--mix .tagify__input::before { + height: auto; + display: none; + line-height: inherit; +} +.tagify--mix .tagify__input::after { + content: none; +} +.tagify--select { + cursor: default; +} +.tagify--select::after { + content: '>'; + opacity: 0.5; + position: absolute; + top: 50%; + right: 0; + bottom: 0; + font: 16px monospace; + line-height: 8px; + height: 8px; + pointer-events: none; + transform: translate(-150%, -50%) scaleX(1.2) rotate(90deg); + transition: 0.2s ease-in-out; +} +.tagify--select[aria-expanded='true']::after { + transform: translate(-150%, -50%) rotate(270deg) scaleY(1.2); +} +.tagify--select[aria-expanded='true'] .tagify__tag__removeBtn { + pointer-events: none; + opacity: 0; + transform: translateX(100%) translateX(5px); +} +.tagify--select .tagify__tag { + flex: 1; + max-width: none; + margin-inline-end: 2em; + margin-block: 0; + padding-block: 5px; + cursor: text; +} +.tagify--select .tagify__tag div::before { + display: none; +} +.tagify--select .tagify__tag + .tagify__input { + display: none; +} +.tagify--empty .tagify__input::before { + transition: 0.2s ease-out; + opacity: 1; + transform: none; + display: inline-block; + width: auto; +} +.tagify--mix .tagify--empty .tagify__input::before { + display: inline-block; +} +.tagify--focus { + --tags-border-color: var(--tags-focus-border-color); + transition: 0s; +} +.tagify--invalid { + --tags-border-color: #d39494; +} +.tagify__dropdown { + position: absolute; + z-index: 9999; + transform: translateY(-1px); + border-top: 1px solid var(--tagify-dd-color-primary); + overflow: hidden; +} +.tagify__dropdown[dir='rtl'] { + transform: translate(-100%, -1px); +} +.tagify__dropdown[placement='top'] { + margin-top: 0; + transform: translateY(-100%); +} +.tagify__dropdown[placement='top'] .tagify__dropdown__wrapper { + border-top-width: 1.1px; + border-bottom-width: 0; +} +.tagify__dropdown[position='text'] { + box-shadow: 0 0 0 3px rgba(var(--tagify-dd-color-primary), 0.1); + font-size: 0.9em; +} +.tagify__dropdown[position='text'] .tagify__dropdown__wrapper { + border-width: 1px; +} +.tagify__dropdown__wrapper { + scroll-behavior: auto; + max-height: var(--tagify-dd-max-height); + overflow: hidden; + overflow-x: hidden; + color: var(--tagify-dd-text-color); + background: var(--tagify-dd-bg-color); + border: 1px solid; + border-color: var(--tagify-dd-color-primary); + border-bottom-width: 1.5px; + border-top-width: 0; + box-shadow: 0 2px 4px -2px rgba(0, 0, 0, 0.2); + transition: 0.3s cubic-bezier(0.5, 0, 0.3, 1), transform 0.15s; + animation: dd-wrapper-show 0s 0.3s forwards; +} +@keyframes dd-wrapper-show { + to { + overflow-y: auto; + } +} +.tagify__dropdown__header:empty { + display: none; +} +.tagify__dropdown__footer { + display: inline-block; + margin-top: 0.5em; + padding: var(--tagify-dd-item-pad); + font-size: 0.7em; + font-style: italic; + opacity: 0.5; +} +.tagify__dropdown__footer:empty { + display: none; +} +.tagify__dropdown--initial .tagify__dropdown__wrapper { + max-height: 20px; + transform: translateY(-1em); +} +.tagify__dropdown--initial[placement='top'] .tagify__dropdown__wrapper { + transform: translateY(2em); +} +.tagify__dropdown__item { + box-sizing: border-box; + padding: var(--tagify-dd-item-pad); + margin: 1px; + white-space: pre-wrap; + cursor: pointer; + border-radius: 2px; + position: relative; + outline: 0; + max-height: 60px; + max-width: 100%; + line-height: normal; + position: relative; +} +.tagify__dropdown__item--active { + background: var(--tagify-dd-color-primary); + color: #fff; +} +.tagify__dropdown__item:active { + filter: brightness(105%); +} +.tagify__dropdown__item--hidden { + padding-top: 0; + padding-bottom: 0; + margin: 0 1px; + pointer-events: none; + overflow: hidden; + max-height: 0; + transition: var(--tagify-dd-item--hidden-duration, 0.3s) !important; +} +.tagify__dropdown__item--hidden > * { + transform: translateY(-100%); + opacity: 0; + transition: inherit; +} +.tagify__dropdown__item--selected::before { + content: '✓'; + font-family: monospace; + position: absolute; + inset-inline-start: 6px; + text-indent: 0; + line-height: 1.1; +} +.tagify__dropdown:has(.tagify__dropdown__item--selected) .tagify__dropdown__item { + text-indent: 1em; +} From c43cf2fb9363f2b54d7ebe5307a224e411ef4fc2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 30 Nov 2025 12:26:29 +0000 Subject: [PATCH 02/56] Auto-format code with fourmolu --- src/Pages/BodyWrapper.hs | 6 +++--- src/Pages/Bots/Discord.hs | 23 +++++++++++++---------- src/Pages/Bots/Slack.hs | 16 ++++++++-------- src/Pages/LogExplorer/Log.hs | 4 ++-- src/Pages/Projects.hs | 32 ++++++++++++++++++++++---------- 5 files changed, 48 insertions(+), 33 deletions(-) diff --git a/src/Pages/BodyWrapper.hs b/src/Pages/BodyWrapper.hs index 4fc70e01f..6be1e2a6b 100644 --- a/src/Pages/BodyWrapper.hs +++ b/src/Pages/BodyWrapper.hs @@ -569,7 +569,7 @@ sideNav sess project pageTitle menuItem = aside_ [class_ "border-r bg-fillWeaker , href_ $ "/p/" <> project.id.toText <> "/settings" ] $ span_ [class_ "w-9 h-9 p-2 flex justify-center items-center rounded-full bg-fillBrand-weak text-textBrand leading-none "] (faSprite_ "gear" "regular" "h-3 w-3") - >> span_ [class_ "hidden group-has-[#sidenav-toggle:checked]/pg:block"] "Settings" + >> span_ [class_ "hidden group-has-[#sidenav-toggle:checked]/pg:block"] "Settings" a_ [ class_ "hover:bg-fillBrand-weak " , target_ "blank" @@ -578,7 +578,7 @@ sideNav sess project pageTitle menuItem = aside_ [class_ "border-r bg-fillWeaker , href_ "https://apitoolkit.io/docs/" ] $ span_ [class_ "w-9 h-9 p-2 flex justify-center items-center rounded-full bg-fillBrand-weak text-textBrand leading-none"] (faSprite_ "circle-question" "regular" "h-3 w-3") - >> span_ [class_ "hidden group-has-[#sidenav-toggle:checked]/pg:block"] "Documentation" + >> span_ [class_ "hidden group-has-[#sidenav-toggle:checked]/pg:block"] "Documentation" -- Dark mode toggle div_ @@ -618,7 +618,7 @@ sideNav sess project pageTitle menuItem = aside_ [class_ "border-r bg-fillWeaker , [__| on click js posthog.reset(); end |] ] $ span_ [class_ "w-9 h-9 p-2 flex justify-center items-center rounded-full bg-fillError-weak text-textError leading-none"] (faSprite_ "arrow-right-from-bracket" "regular" "h-3 w-3") - >> span_ [class_ "hidden group-has-[#sidenav-toggle:checked]/pg:block"] "Logout" + >> span_ [class_ "hidden group-has-[#sidenav-toggle:checked]/pg:block"] "Logout" -- mapM_ renderNavBottomItem $ navBottomList project.id.toText diff --git a/src/Pages/Bots/Discord.hs b/src/Pages/Bots/Discord.hs index 9c27f22b8..f12f486fe 100644 --- a/src/Pages/Bots/Discord.hs +++ b/src/Pages/Bots/Discord.hs @@ -176,17 +176,17 @@ instance AE.FromJSON InteractionData where Just 3 -> MessageComponentData <$> v - AE..: "component_type" + AE..: "component_type" <*> v - AE..: "custom_id" + AE..: "custom_id" <*> v - AE..: "values" + AE..: "values" _ -> CommandData <$> v - AE..: "name" + AE..: "name" <*> v - AE..:? "options" + AE..:? "options" data InteractionOption = InteractionOption @@ -208,9 +208,12 @@ data DiscordChannel = DiscordChannel instance AE.FromJSON DiscordChannel where parseJSON = AE.withObject "DiscordChannel" $ \o -> DiscordChannel - <$> o AE..: "id" - <*> o AE..: "name" - <*> o AE..: "type" + <$> o + AE..: "id" + <*> o + AE..: "name" + <*> o + AE..: "type" getDiscordChannels :: HTTP :> es => Text -> Text -> Eff es [DiscordChannel] @@ -405,8 +408,8 @@ threadsPrompt msgs question = prompt , "- the user query is the main one to answer, but earlier messages may contain important clarifications or parameters." , "\nPrevious thread messages in json:\n" ] - <> [msgJson] - <> ["\n\nUser query: " <> question] + <> [msgJson] + <> ["\n\nUser query: " <> question] prompt = systemPrompt <> threadPrompt diff --git a/src/Pages/Bots/Slack.hs b/src/Pages/Bots/Slack.hs index 240d878c4..fc9420dc7 100644 --- a/src/Pages/Bots/Slack.hs +++ b/src/Pages/Bots/Slack.hs @@ -525,17 +525,17 @@ instance AE.FromJSON SlackEventPayload where "event_callback" -> EventCallback <$> v - AE..: "token" + AE..: "token" <*> v - AE..: "team_id" + AE..: "team_id" <*> v - AE..: "api_app_id" + AE..: "api_app_id" <*> v - AE..: "event" + AE..: "event" <*> v - AE..: "event_id" + AE..: "event_id" <*> v - AE..: "event_time" + AE..: "event_time" other -> fail $ "Unsupported Slack event type: " ++ show other @@ -710,7 +710,7 @@ threadsPrompt msgs question = prompt , "- the user query is the main one to answer, but earlier messages may contain important clarifications or parameters." , "\nPrevious thread messages in json:\n" ] - <> [msgJson] - <> ["\n\nUser query: " <> question] + <> [msgJson] + <> ["\n\nUser query: " <> question] prompt = systemPrompt <> threadPrompt diff --git a/src/Pages/LogExplorer/Log.hs b/src/Pages/LogExplorer/Log.hs index 84db6745c..03fcea617 100644 --- a/src/Pages/LogExplorer/Log.hs +++ b/src/Pages/LogExplorer/Log.hs @@ -1098,8 +1098,8 @@ alertConfigurationForm_ project alertM = do }) end|] ] - ++ [required_ "" | req] - ++ [value_ (maybe "" (show) vM) | isJust vM] + ++ [required_ "" | req] + ++ [value_ (maybe "" (show) vM) | isJust vM] span_ [class_ "absolute right-2 top-1/2 -translate-y-1/2 text-xs text-textWeak"] "events" thresholdInput "alertThreshold" "bg-fillError-strong" "Alert threshold" True (fmap (.alertThreshold) alertM) diff --git a/src/Pages/Projects.hs b/src/Pages/Projects.hs index 380eb2e45..ca4607ca7 100644 --- a/src/Pages/Projects.hs +++ b/src/Pages/Projects.hs @@ -469,12 +469,12 @@ manageMembersPostH pid onboardingM form = do unless (null uAndPOldAndChanged) $ void - . dbtToEff + . dbtToEff $ ProjectMembers.updateProjectMembersPermissons uAndPOldAndChanged unless (null deletedUAndP) $ void - . dbtToEff + . dbtToEff $ ProjectMembers.softDeleteProjectMembers deletedUAndP projMembersLatest <- dbtToEff $ ProjectMembers.selectActiveProjectMembers pid @@ -505,14 +505,26 @@ data TeamForm = TeamForm instance AE.FromJSON TeamForm where parseJSON = AE.withObject "TeamForm" $ \o -> do TeamForm - <$> o AE..: "teamName" - <*> o AE..: "teamDescription" - <*> o AE..: "teamHandle" - <*> o AE..:? "teamMembers" AE..!= V.empty - <*> o AE..:? "notifEmails" AE..!= V.empty - <*> o AE..:? "slackChannels" AE..!= V.empty - <*> o AE..:? "discordChannels" AE..!= V.empty - <*> o AE..:? "teamId" + <$> o + AE..: "teamName" + <*> o + AE..: "teamDescription" + <*> o + AE..: "teamHandle" + <*> o + AE..:? "teamMembers" + AE..!= V.empty + <*> o + AE..:? "notifEmails" + AE..!= V.empty + <*> o + AE..:? "slackChannels" + AE..!= V.empty + <*> o + AE..:? "discordChannels" + AE..!= V.empty + <*> o + AE..:? "teamId" manageTeamPostH :: Projects.ProjectId -> TeamForm -> ATAuthCtx (RespHeaders (Html ())) From d80b0c0dc4fba34791d9c84cb9a3d5a8efdc4deb Mon Sep 17 00:00:00 2001 From: Yussif Mohammed Date: Sun, 30 Nov 2025 17:23:48 +0000 Subject: [PATCH 03/56] fix htmx json encoder extension --- static/public/assets/deps/htmx/json-enc-2.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/static/public/assets/deps/htmx/json-enc-2.js b/static/public/assets/deps/htmx/json-enc-2.js index 3538c8737..235088a59 100644 --- a/static/public/assets/deps/htmx/json-enc-2.js +++ b/static/public/assets/deps/htmx/json-enc-2.js @@ -18,18 +18,21 @@ const object = {} parameters.forEach(function (value, key) { // FormData encodes values as strings, restore hx-vals/hx-vars with their initial types - const typedValue = Object.hasOwn(vals, key) ? vals[key] : value - if (Object.hasOwn(object, key)) { - if (!Array.isArray(object[key])) { - object[key] = [object[key]] + typedValue = value + if (!Object.hasOwn(vals, key)) { + if (Object.hasOwn(object, key)) { + if (!Array.isArray(object[key])) { + object[key] = [object[key]] + } else { + object[key].push(typedValue) + } + } else { + object[key] = typedValue } - object[key].push(typedValue) - } else { - object[key] = typedValue } }) - return JSON.stringify(object) + return JSON.stringify({ object, ...vals }) }, }) })() From aadc57d219a179fb9e05f3df64d15ee4cfeba108 Mon Sep 17 00:00:00 2001 From: Yussif Mohammed Date: Sun, 30 Nov 2025 17:25:07 +0000 Subject: [PATCH 04/56] improve team list --- src/Models/Projects/ProjectMembers.hs | 75 ++++++++++++++++++--------- src/Pages/Projects.hs | 70 +++++++++++++++++-------- 2 files changed, 99 insertions(+), 46 deletions(-) diff --git a/src/Models/Projects/ProjectMembers.hs b/src/Models/Projects/ProjectMembers.hs index 5ba332870..492534972 100644 --- a/src/Models/Projects/ProjectMembers.hs +++ b/src/Models/Projects/ProjectMembers.hs @@ -13,6 +13,7 @@ module Models.Projects.ProjectMembers ( getTeamByHandle, TeamVM (..), Team (..), + TeamMemberVM (..), ) where import Control.Error (note) @@ -22,7 +23,7 @@ import Data.Default.Instances () import Data.Time (ZonedTime) import Data.UUID qualified as UUID import Data.Vector qualified as V -import Database.PostgreSQL.Entity.DBT (query) +import Database.PostgreSQL.Entity.DBT (query, queryOne) import Database.PostgreSQL.Entity.Types ( CamelToSnake, Entity, @@ -194,13 +195,32 @@ data Team = Team deriving anyclass (FromRow, NFData) -getTeams :: Projects.ProjectId -> DBT IO (V.Vector Team) +getTeams :: Projects.ProjectId -> DBT IO (V.Vector TeamVM) getTeams pid = query q (Only pid) where q = - [sql| SELECT id, name, description, handle, members, notify_emails, slack_channels, discord_channels - FROM projects.teams - WHERE project_id = ? |] + [sql| + SELECT + t.id, + t.name, + t.handle, + t.description, + t.notify_emails, + t.slack_channels, + t.discord_channels, +ARRAY( + SELECT jsonb_build_object( + 'memberId', u.id, + 'memberName', concat_ws(' ', u.first_name, u.last_name), + 'memberEmail', u.email, + 'memberAvatar', u.display_image_url + ) + FROM unnest(t.members) AS mid + JOIN users.users u ON u.id = mid +) AS members + FROM projects.teams t + WHERE t.project_id = ? + |] data TeamVM = TeamVM @@ -221,14 +241,24 @@ data TeamMemberVM = TeamMemberVM { memberId :: UUID.UUID , memberEmail :: CI Text , memberName :: Text - , memberAvatar :: Maybe Text + , memberAvatar :: Text } deriving stock (Eq, Generic, Show) - deriving anyclass (FromField, NFData) + deriving anyclass (AE.FromJSON, NFData) -getTeamByHandle :: Projects.ProjectId -> Text -> DBT IO (V.Vector TeamVM) -getTeamByHandle pid handle = query q (pid, handle) +instance FromField TeamMemberVM where + fromField f mdata = + case mdata of + Nothing -> returnError UnexpectedNull f "" + Just bs -> + case AE.eitherDecodeStrict' bs of + Right a -> pure a + Left err -> returnError ConversionFailed f ("Failed to parse JSON for TeamMemberVM: " <> err) + + +getTeamByHandle :: Projects.ProjectId -> Text -> DBT IO (Maybe TeamVM) +getTeamByHandle pid handle = queryOne q (pid, handle) where q = [sql| @@ -240,22 +270,17 @@ getTeamByHandle pid handle = query q (pid, handle) t.notify_emails, t.slack_channels, t.discord_channels, - COALESCE( - ( - SELECT jsonb_agg( - jsonb_build_object( - 'memberId', u.id, - 'memberName', u.first_name <> ' ' <> u.last_name, - 'memberEmail', u.email, - 'memberAvatar', u.avatar - ) - ) - FROM unnest(t.members) AS mid - JOIN users.users u ON u.id = mid - ), - '[]'::jsonb - ) AS members - FROM teams t +ARRAY( + SELECT jsonb_build_object( + 'memberId', u.id, + 'memberName', concat_ws(' ', u.first_name, u.last_name), + 'memberEmail', u.email, + 'memberAvatar', u.display_image_url + ) + FROM unnest(t.members) AS mid + JOIN users.users u ON u.id = mid +) AS members + FROM projects.teams t WHERE t.project_id = ? AND t.handle = ? |] diff --git a/src/Pages/Projects.hs b/src/Pages/Projects.hs index ca4607ca7..d8d489520 100644 --- a/src/Pages/Projects.hs +++ b/src/Pages/Projects.hs @@ -74,7 +74,7 @@ import Lucid.Hyperscript (__) import Models.Apis.Slack (SlackData, getDiscordDataByProjectId, getProjectSlackData) import Models.Apis.Slack qualified as Slack import Models.Projects.ProjectApiKeys qualified as ProjectApiKeys -import Models.Projects.ProjectMembers (TeamVM (..)) +import Models.Projects.ProjectMembers (TeamMemberVM (..), TeamVM (..)) import Models.Projects.ProjectMembers qualified as ProjectMembers import Models.Projects.Projects qualified as Projects import Models.Users.Sessions qualified as Sessions @@ -579,9 +579,9 @@ manageTeamsGetH pid layoutM = do addRespHeaders $ bodyWrapper bwconf $ manageTeamsPage pid projMembers channels discordChannels teams -manageTeamsPage :: Projects.ProjectId -> V.Vector ProjectMembers.ProjectMemberVM -> [SlackP.SlackChannel] -> [Discord.DiscordChannel] -> V.Vector ProjectMembers.Team -> Html () +manageTeamsPage :: Projects.ProjectId -> V.Vector ProjectMembers.ProjectMemberVM -> [SlackP.SlackChannel] -> [Discord.DiscordChannel] -> V.Vector ProjectMembers.TeamVM -> Html () manageTeamsPage pid projMembers channels discordChannels teams = do - let whiteList = decodeUtf8 $ AE.encode $ (\x -> AE.object ["name" AE..= (x.first_name <> " " <> x.last_name), "email" AE..= x.email, "value" AE..= x.id]) <$> projMembers + let whiteList = decodeUtf8 $ AE.encode $ (\x -> AE.object ["name" AE..= (x.first_name <> " " <> x.last_name), "email" AE..= x.email, "value" AE..= x.userId]) <$> projMembers let channelWhiteList = decodeUtf8 $ AE.encode $ (\x -> AE.object ["name" AE..= ("#" <> x.channelName), "value" AE..= x.channelId]) <$> channels let discordWhiteList = decodeUtf8 $ AE.encode $ (\x -> AE.object ["name" AE..= ("#" <> x.channelName), "value" AE..= x.channelId]) <$> discordChannels section_ [id_ "main-content", class_ "w-full py-8"] do @@ -598,24 +598,36 @@ manageTeamsPage pid projMembers channels discordChannels teams = do faSprite_ "magnifying-glass" "regular" "h-4 w-4 text-textWeak" input_ [type_ "text", placeholder_ "Search teams...", class_ ""] span_ [class_ "text-textWeak text-sm"] $ (show (V.length teams) <> " teams found") - div_ [class_ "mt-6 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6"] $ mapM_ (\t -> teamCard pid t whiteList channelWhiteList discordWhiteList) (V.toList teams) + div_ [class_ "mt-6 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-2 gap-4"] $ mapM_ (\t -> teamCard pid t whiteList channelWhiteList discordWhiteList) (V.toList teams) -teamCard :: Projects.ProjectId -> ProjectMembers.Team -> Text -> Text -> Text -> Html () +teamCard :: Projects.ProjectId -> ProjectMembers.TeamVM -> Text -> Text -> Text -> Html () teamCard pid team whiteList channelWhiteList discordWhiteList = do - a_ [href_ $ "/p/" <> pid.toText <> "/manage_teams/" <> team.handle, class_ "bg-base-100 border border-strokeWeak rounded-xl shadow-sm hover:shadow-md transition-shadow duration-200 overflow-hidden"] do - div_ [class_ "p-5 pb-3"] do - div_ [class_ "flex justify-between items-start mb-3"] do - div_ [class_ "flex-1 min-w-0"] do - h4_ [class_ "text-textStrong font-semibold text-lg"] $ toHtml team.name - p_ [class_ "text-textWeak text-sm mt-1 line-clamp-2"] $ toHtml team.description + div_ [class_ "border border-strokeWeak rounded-xl shadow-sm hover:shadow-md transition-shadow duration-200 overflow-hidden"] do + div_ [class_ "p-5 pb-3 flex flex-col gap-4"] do + div_ [class_ "flex justify-between center"] do + a_ [href_ $ "/p/" <> pid.toText <> "/manage_teams/" <> team.handle, class_ "flex items-center gap-4 min-w-0"] do + div_ [class_ "rounded-full border border-strokeWeak p-3"] do + span_ [class_ "text-xl font-bold"] "BS" + div_ [] do + h4_ [class_ "text-textStrong font-semibold"] $ toHtml team.name + span_ [class_ "text-textWeak text-sm"] $ toHtml team.handle label_ [class_ "btn btn-ghost btn-sm", Lucid.for_ (team.handle <> "-new-team-modal")] "Edit" input_ [type_ "checkbox", id_ (team.handle <> "-new-team-modal"), class_ "modal-toggle"] teamModal pid (Just team) whiteList channelWhiteList discordWhiteList + div_ [] do + p_ [class_ "text-textWeak text-sm mt-1 line-clamp-2"] $ toHtml team.description div_ [class_ "flex items-center justify-between text-sm text-textWeak"] do div_ [class_ "flex items-center gap-2"] do - faSprite_ "users" "regular" "h-3.5 w-3.5" - span_ [] $ toHtml $ (show $ V.length team.members) <> " members" + div_ [class_ "flex items-center gap-1", term "data-tippy-content" "Members"] do + faSprite_ "users" "regular" "h-3.5 w-3.5" + span_ [] $ toHtml $ show $ V.length team.members + div_ [class_ "flex items-center gap-1", term "data-tippy-content" "Dashboards"] do + faSprite_ "dashboard" "regular" "h-3 w-3" + span_ [] $ toHtml $ show $ V.length team.members + div_ [class_ "flex items-center gap-1", term "data-tippy-content" "Monitors"] do + faSprite_ "information" "regular" "h-3.5 w-3.5" + span_ [] $ toHtml $ show $ V.length team.members div_ [class_ "flex items-center gap-2"] do when (not $ V.null team.slack_channels) do faSprite_ "slack" "regular" "h-3.5 w-3.5" @@ -623,6 +635,12 @@ teamCard pid team whiteList channelWhiteList discordWhiteList = do faSprite_ "discord" "regular" "h-3.5 w-3.5" when (not $ V.null team.notify_emails) do faSprite_ "envelope" "regular" "h-3.5 w-3.5" + div_ [class_ "flex justify-between items-center text-textWeak text-xs mt-2"] do + toHtml $ "Created " <> "22-10-220" + div_ [class_ "inline-block flex -space-x-2"] do + forM_ team.members $ \m -> do + div_ [class_ "inline-block mx-0.5", term "data-tippy-content" (m.memberName)] + $ img_ [class_ "inline-block h-6 w-6 rounded-full ", src_ m.memberAvatar, alt_ "User avatar"] teamGetH :: Projects.ProjectId -> Text -> ATAuthCtx (RespHeaders (Html ())) @@ -633,22 +651,31 @@ teamGetH pid handle = do let bwconf = (def :: BWConfig) { sessM = Just sess - , pageTitle = "Manage teams" + , pageTitle = "Team details" , currProject = Just project - , isSettingsPage = True , config = appCtx.config } - addRespHeaders $ bodyWrapper bwconf $ teamPage pid + case teamVm of + Just team -> addRespHeaders $ bodyWrapper bwconf $ teamPage pid team + Nothing -> addRespHeaders $ bodyWrapper bwconf $ teamPageNF pid handle -teamPage :: Projects.ProjectId -> Html () -teamPage pid = do +teamPage :: Projects.ProjectId -> ProjectMembers.TeamVM -> Html () +teamPage pid team = do section_ [id_ "main-content", class_ "w-full py-16"] do div_ [class_ "p-6 w-[606px] mx-auto"] do h2_ [class_ "text-textStrong mb-4 text-xl font-semibold"] "Manage Team" p_ [class_ "text-textWeak text-sm leading-tight"] "We'll email them instructions and a link to sign in" +teamPageNF :: Projects.ProjectId -> Text -> Html () +teamPageNF pid handle = do + section_ [id_ "main-content", class_ "w-full py-16"] do + div_ [class_ "p-6 w-[606px] mx-auto"] do + h2_ [class_ "text-textStrong mb-4 text-xl font-semibold"] $ "Team not found: " <> toHtml handle + p_ [class_ "text-textWeak text-sm leading-tight"] "We couldn't find the team you're looking for." + + manageMembersGetH :: Projects.ProjectId -> ATAuthCtx (RespHeaders ManageMembers) manageMembersGetH pid = do (sess, project) <- Sessions.sessionAndProject pid @@ -1217,14 +1244,14 @@ data NotificationChannel -- Main Modal Component -teamModal :: Projects.ProjectId -> Maybe ProjectMembers.Team -> Text -> Text -> Text -> Html () +teamModal :: Projects.ProjectId -> Maybe ProjectMembers.TeamVM -> Text -> Text -> Text -> Html () teamModal pid team whiteList channelWhiteList discordWhiteList = do let name = maybe "" (.name) team let handle = maybe "" (.handle) team let description = maybe "" (.description) team let teamId = fmap (.id) team let prefix = maybe "n" (\x -> x.handle) team - let membersTags = decodeUtf8 $ AE.encode $ maybe [] (\t -> ((.toText) <$> t.members)) team + let membersTags = decodeUtf8 $ AE.encode $ maybe [] (\t -> ((\m -> UUID.toText m.memberId) <$> t.members)) team let notifEmails = decodeUtf8 $ AE.encode $ maybe [] (.notify_emails) team let slackChannels = decodeUtf8 $ AE.encode $ maybe [] (.slack_channels) team let discordChannels = decodeUtf8 $ AE.encode $ maybe [] (.discord_channels) team @@ -1307,12 +1334,13 @@ var customTagTemplate = { var dropdown = {mapValueTo: 'name', searchKeys: ['name', 'value']} function getTagValues(prefix) { - return { + const val = { teamMembers: window[`$${prefix}-membersTagify`].value.map(item => item.value), notifEmails: window[`$${prefix}-notifEmailsTagify`].value.map(item => item.value), slackChannels: window[`$${prefix}-slackTagify`].value.map(item => item.value), discordChannels: window[`$${prefix}-discordTagify`].value.map(item => item.value) } + return val } // Initialize all Tagify instances From 27afa7c66bbea06a0ae83810ad728dfecc285edd Mon Sep 17 00:00:00 2001 From: Yussif Mohammed Date: Sun, 30 Nov 2025 21:31:46 +0000 Subject: [PATCH 05/56] team view side page, alerts and dashbaord next --- src/Models/Projects/ProjectMembers.hs | 10 ++- src/Pages/Projects.hs | 89 ++++++++++++++++++++++++--- 2 files changed, 88 insertions(+), 11 deletions(-) diff --git a/src/Models/Projects/ProjectMembers.hs b/src/Models/Projects/ProjectMembers.hs index 492534972..2a9c24264 100644 --- a/src/Models/Projects/ProjectMembers.hs +++ b/src/Models/Projects/ProjectMembers.hs @@ -20,7 +20,7 @@ import Control.Error (note) import Data.Aeson qualified as AE import Data.CaseInsensitive (CI) import Data.Default.Instances () -import Data.Time (ZonedTime) +import Data.Time (UTCTime, ZonedTime) import Data.UUID qualified as UUID import Data.Vector qualified as V import Database.PostgreSQL.Entity.DBT (query, queryOne) @@ -202,6 +202,8 @@ getTeams pid = query q (Only pid) [sql| SELECT t.id, + t.created_at, + t.updated_at, t.name, t.handle, t.description, @@ -225,6 +227,8 @@ ARRAY( data TeamVM = TeamVM { id :: UUID.UUID + , created_at :: UTCTime + , updated_at :: UTCTime , name :: Text , handle :: Text , description :: Text @@ -239,7 +243,7 @@ data TeamVM = TeamVM data TeamMemberVM = TeamMemberVM { memberId :: UUID.UUID - , memberEmail :: CI Text + , memberEmail :: Text , memberName :: Text , memberAvatar :: Text } @@ -264,6 +268,8 @@ getTeamByHandle pid handle = queryOne q (pid, handle) [sql| SELECT t.id, + t.created_at, + t.updated_at, t.name, t.handle, t.description, diff --git a/src/Pages/Projects.hs b/src/Pages/Projects.hs index d8d489520..7ccf3d87a 100644 --- a/src/Pages/Projects.hs +++ b/src/Pages/Projects.hs @@ -55,6 +55,7 @@ import Data.Effectful.Wreq qualified as W import Data.List.Unique (uniq) import Data.Pool (withResource) import Data.Text qualified as T +import Data.Time import Data.UUID qualified as RealUUID import Data.Valor (Valor, check1, failIf, validateM) import Data.Valor qualified as Valor @@ -85,6 +86,7 @@ import OddJobs.Job (createJob) import Pages.BodyWrapper (BWConfig (..), PageCtx (..), bodyWrapper) import Pages.Bots.Discord qualified as Discord import Pages.Bots.Slack (channels, getSlackChannels) +import Pages.Bots.Slack qualified as Slack import Pages.Bots.Slack qualified as SlackP import Pages.Components (paymentPlanPicker) import Pkg.Components.Widget (Widget (..), WidgetType (..), widget_) @@ -98,7 +100,7 @@ import Servant.API.ResponseHeaders (Headers) import Servant.Server (err302, errHeaders) import System.Config (AuthContext (..), EnvConfig (..)) import System.Types (ATAuthCtx, RespHeaders, addErrorToast, addRespHeaders, addSuccessToast, addTriggerEvent, redirectCS) -import Utils (faSprite_, insertIfNotExist, isDemoAndNotSudo, lookupValueText) +import Utils (faSprite_, formatUTC, insertIfNotExist, isDemoAndNotSudo, lookupValueText) import Web.FormUrlEncoded (FromForm) import "base64" Data.ByteString.Base64 qualified as B64 @@ -636,7 +638,7 @@ teamCard pid team whiteList channelWhiteList discordWhiteList = do when (not $ V.null team.notify_emails) do faSprite_ "envelope" "regular" "h-3.5 w-3.5" div_ [class_ "flex justify-between items-center text-textWeak text-xs mt-2"] do - toHtml $ "Created " <> "22-10-220" + toHtml $ "Created " <> (toText $ formatTime defaultTimeLocale "%Y-%m-%dT%H:%M:%S%6QZ" team.created_at) div_ [class_ "inline-block flex -space-x-2"] do forM_ team.members $ \m -> do div_ [class_ "inline-block mx-0.5", term "data-tippy-content" (m.memberName)] @@ -648,6 +650,22 @@ teamGetH pid handle = do (sess, project) <- Sessions.sessionAndProject pid appCtx <- ask @AuthContext teamVm <- dbtToEff $ ProjectMembers.getTeamByHandle pid handle + projMembers <- dbtToEff $ ProjectMembers.selectActiveProjectMembers pid + slackDataM <- Slack.getProjectSlackData pid + channels <- case slackDataM of + Just slackData -> do + channels' <- SlackP.getSlackChannels appCtx.env.slackBotToken slackData.teamId + case channels' of + Just chs -> return chs.channels + Nothing -> return [] + Nothing -> return [] + + discordDataM <- Slack.getDiscordDataByProjectId pid + discordChannels <- case discordDataM of + Just discordData -> do + channels' <- Discord.getDiscordChannels appCtx.env.discordBotToken discordData.guildId + return channels' + Nothing -> return [] let bwconf = (def :: BWConfig) { sessM = Just sess @@ -656,16 +674,69 @@ teamGetH pid handle = do , config = appCtx.config } case teamVm of - Just team -> addRespHeaders $ bodyWrapper bwconf $ teamPage pid team + Just team -> addRespHeaders $ bodyWrapper bwconf $ teamPage pid team projMembers channels discordChannels Nothing -> addRespHeaders $ bodyWrapper bwconf $ teamPageNF pid handle -teamPage :: Projects.ProjectId -> ProjectMembers.TeamVM -> Html () -teamPage pid team = do - section_ [id_ "main-content", class_ "w-full py-16"] do - div_ [class_ "p-6 w-[606px] mx-auto"] do - h2_ [class_ "text-textStrong mb-4 text-xl font-semibold"] "Manage Team" - p_ [class_ "text-textWeak text-sm leading-tight"] "We'll email them instructions and a link to sign in" +teamPage :: Projects.ProjectId -> ProjectMembers.TeamVM -> V.Vector ProjectMembers.ProjectMemberVM -> [Slack.SlackChannel] -> [Discord.DiscordChannel] -> Html () +teamPage pid team projMembers slackChannels discordChannels = do + section_ [id_ "main-content", class_ "w-full h-full"] do + div_ [class_ "flex h-full border-t border-strokeWeak"] do + div_ [class_ "p-4 w-4/12 space-y-6 mx-auto h-full overflow-y-auto"] do + div_ [class_ "flex items-center gap-3"] do + h2_ [class_ "text-xl font-semibold"] $ toHtml team.name + span_ [class_ "text-textWeak flex items-center gap-1 text-sm"] do + faSprite_ "copy" "regular" "w-3 h-3" + toHtml team.handle + div_ [] do + p_ [class_ "text-textWeak text-sm"] $ toHtml team.description + div_ [class_ "rounded-lg p-2 border border-strokeWeak"] do + span_ [class_ "text-sm flex items-center gap-2 font-semibold py-2"] do + faSprite_ "users" "regular" "h-4 w-4" + toHtml $ "Members" + span_ [class_ "text-textWeak"] $ ("(" <> show (V.length team.members) <> ")") + + div_ [] do + forM_ team.members \m -> do + div_ [class_ "flex flex-col gap-1 py-3 border-t border-strokeWeak"] do + div_ [class_ "flex gap-2 text-sm"] do + img_ [src_ m.memberAvatar, class_ "w-5 h-5 rounded-full border border-strokeWeak"] + span_ [] $ toHtml m.memberName + span_ [class_ "text-textWeak text-xs"] $ toHtml m.memberEmail + + div_ [class_ "p-2 rounded-lg border border-strokeWeak"] do + span_ [class_ "text-sm flex items-center gap-2 py-2 font-semibold border-b border-strokeWeak"] do + faSprite_ "bell" "regular" "h-4 w-4" + "Notifications" + div_ [] do + div_ [class_ "flex flex-col gap-2 py-3 border-t border-strokeWeak"] do + div_ [class_ "flex items-center text-sm gap-2 font-medium"] do + faSprite_ "envelope" "regular" "h-4 w-4" + "Email addresses" + div_ [class_ "flex items-center gap-2 text-xs text-textWeak"] do + when (V.null team.notify_emails) $ span_ [] "No emails added" + forM_ team.notify_emails \e -> span_ [] $ toHtml e + div_ [class_ "flex flex-col gap-2 py-3 border-t border-strokeWeak"] do + div_ [class_ "flex items-center text-sm gap-2 font-medium"] do + faSprite_ "slack" "solid" "h-4 w-4" + "Slack channels" + div_ [class_ "flex items-center gap-2 text-xs text-textWeak"] do + when (V.null team.slack_channels) $ span_ [] "No slack channel configured" + forM_ team.slack_channels \e -> do + let tar = maybe e (.channelName) $ find (\x -> x.channelId == e) slackChannels + span_ [] $ toHtml tar + div_ [class_ "flex flex-col gap-2 py-3 border-t border-strokeWeak"] do + div_ [class_ "flex items-center text-sm gap-2 font-medium"] do + faSprite_ "discord" "solid" "h-4 w-4" + "Discord channels" + div_ [class_ "flex items-center gap-2 text-xs text-textWeak"] do + when (V.null team.discord_channels) $ span_ [] "No discord channel configured" + forM_ team.discord_channels \e -> do + let tar = maybe e (.channelName) $ find (\x -> x.channelId == e) discordChannels + span_ [] $ toHtml tar + + div_ [class_ "h-full w-8/12 overflow-y-auto"] do + div_ [class_ "h-[1000px] w-full bg-red-500"] pass teamPageNF :: Projects.ProjectId -> Text -> Html () From ce23bb7660b944e87c30a29c23747a5f9fce3e56 Mon Sep 17 00:00:00 2001 From: Yussif Mohammed Date: Sun, 30 Nov 2025 21:49:40 +0000 Subject: [PATCH 06/56] yeah well --- src/Pages/Projects.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Pages/Projects.hs b/src/Pages/Projects.hs index 7ccf3d87a..60e91970c 100644 --- a/src/Pages/Projects.hs +++ b/src/Pages/Projects.hs @@ -735,8 +735,8 @@ teamPage pid team projMembers slackChannels discordChannels = do let tar = maybe e (.channelName) $ find (\x -> x.channelId == e) discordChannels span_ [] $ toHtml tar - div_ [class_ "h-full w-8/12 overflow-y-auto"] do - div_ [class_ "h-[1000px] w-full bg-red-500"] pass + div_ [class_ "h-full w-8/12 overflow-y-auto border-l p-2"] do + div_ [class_ "h-[1000px] w-full"] pass teamPageNF :: Projects.ProjectId -> Text -> Html () From 84d6fa71eb668d9acbdd3152bd8d69d644969356 Mon Sep 17 00:00:00 2001 From: Yussif Mohammed Date: Mon, 1 Dec 2025 08:57:11 +0000 Subject: [PATCH 07/56] validation checks and fixes --- src/Pages/Projects.hs | 292 +++++++++++++++---- src/System/Types.hs | 9 + src/Web/Routes.hs | 4 +- static/public/assets/deps/htmx/json-enc-2.js | 2 +- 4 files changed, 241 insertions(+), 66 deletions(-) diff --git a/src/Pages/Projects.hs b/src/Pages/Projects.hs index 60e91970c..c8dd47fc8 100644 --- a/src/Pages/Projects.hs +++ b/src/Pages/Projects.hs @@ -47,6 +47,7 @@ import Data.Aeson qualified as AE import Data.Base64.Types qualified as B64 import Data.CaseInsensitive (original) import Data.CaseInsensitive qualified as CI +import Data.Char (isAlphaNum, isDigit, isLower) import Data.Default (Default (..)) import Data.Effectful.UUID (UUID) import Data.Effectful.UUID qualified as UUID @@ -70,7 +71,7 @@ import GHC.Records (HasField (getField)) import Lucid import Lucid (div_) import Lucid.Htmx -import Lucid.Htmx (hxPost_) +import Lucid.Htmx (hxPost_, hxSelect_, hxSwapOob_) import Lucid.Hyperscript (__) import Models.Apis.Slack (SlackData, getDiscordDataByProjectId, getProjectSlackData) import Models.Apis.Slack qualified as Slack @@ -99,7 +100,7 @@ import Servant.API (Header) import Servant.API.ResponseHeaders (Headers) import Servant.Server (err302, errHeaders) import System.Config (AuthContext (..), EnvConfig (..)) -import System.Types (ATAuthCtx, RespHeaders, addErrorToast, addRespHeaders, addSuccessToast, addTriggerEvent, redirectCS) +import System.Types (ATAuthCtx, RespHeaders, addErrorToast, addRespHeaders, addReswap, addSuccessToast, addTriggerEvent, redirectCS) import Utils (faSprite_, formatUTC, insertIfNotExist, isDemoAndNotSudo, lookupValueText) import Web.FormUrlEncoded (FromForm) import "base64" Data.ByteString.Base64 qualified as B64 @@ -325,6 +326,28 @@ validateWhatsapp :: [Text] -> [Text] -> Either Text () validateWhatsapp notificationsChannel numbers = if "phone" `elem` notificationsChannel && null numbers then Left "Provide at least one whatsapp number" else Right () +validateTeamDetails :: Text -> Text -> Either Text () +validateTeamDetails name handle = do + validateName name + validateHandle handle + pure () + where + validNameChar c = isAlphaNum c || c == ' ' || c == '-' || c == '_' + validHandleChar c = isLower c || isDigit c || c == '-' + validateName n + | T.null n = Left "Team name is required" + | T.length n < 3 = Left "Team name must be at least 3 characters" + | not (T.all validNameChar n) = + Left "Invalid characters in team name" + | otherwise = Right () + validateHandle h + | T.null h = Left "Handle is required" + | not (validHandleChar <$> T.unpack h & and) = + Left "Handle must be lowercase, no spaces, and hyphens only" + | not (isLower (T.head h)) = Left "Handle must start with a lowercase letter" + | otherwise = Right () + + integrationsBody :: Sessions.PersistentSession -> EnvConfig -> Bool -> CreateProjectForm -> Maybe (V.Vector Projects.NotificationChannel) -> V.Vector Text -> Maybe SlackData -> Html () integrationsBody sess envCfg isUpdate cp notifChannel phones slackData = do section_ [id_ "main-content", class_ "p-3 py-5 sm:p-6 overflow-y-scroll h-full"] do @@ -471,12 +494,12 @@ manageMembersPostH pid onboardingM form = do unless (null uAndPOldAndChanged) $ void - . dbtToEff + . dbtToEff $ ProjectMembers.updateProjectMembersPermissons uAndPOldAndChanged unless (null deletedUAndP) $ void - . dbtToEff + . dbtToEff $ ProjectMembers.softDeleteProjectMembers deletedUAndP projMembersLatest <- dbtToEff $ ProjectMembers.selectActiveProjectMembers pid @@ -508,41 +531,50 @@ instance AE.FromJSON TeamForm where parseJSON = AE.withObject "TeamForm" $ \o -> do TeamForm <$> o - AE..: "teamName" + AE..: "teamName" <*> o - AE..: "teamDescription" + AE..: "teamDescription" <*> o - AE..: "teamHandle" + AE..: "teamHandle" <*> o - AE..:? "teamMembers" - AE..!= V.empty + AE..:? "teamMembers" + AE..!= V.empty <*> o - AE..:? "notifEmails" - AE..!= V.empty + AE..:? "notifEmails" + AE..!= V.empty <*> o - AE..:? "slackChannels" - AE..!= V.empty + AE..:? "slackChannels" + AE..!= V.empty <*> o - AE..:? "discordChannels" - AE..!= V.empty + AE..:? "discordChannels" + AE..!= V.empty <*> o - AE..:? "teamId" + AE..:? "teamId" -manageTeamPostH :: Projects.ProjectId -> TeamForm -> ATAuthCtx (RespHeaders (Html ())) -manageTeamPostH pid TeamForm{teamName, teamDescription, teamHandle, teamMembers, notifEmails, slackChannels, discordChannels, teamId} = do - rs <- case teamId of - Just tid -> do - _ <- dbtToEff $ ProjectMembers.updateTeam pid tid teamName teamDescription teamHandle teamMembers notifEmails slackChannels discordChannels - addSuccessToast "Team updated successfully" Nothing - html <- manageTeamsGetH pid (Just "from_post") - return html - Nothing -> do - _ <- dbtToEff $ ProjectMembers.createTeam pid teamName teamDescription teamHandle teamMembers notifEmails slackChannels discordChannels - addSuccessToast "Team saved successfully" Nothing - html <- manageTeamsGetH pid (Just "from_post") - return html - return rs +manageTeamPostH :: Projects.ProjectId -> TeamForm -> Maybe Text -> ATAuthCtx (RespHeaders (Html ())) +manageTeamPostH pid TeamForm{teamName, teamDescription, teamHandle, teamMembers, notifEmails, slackChannels, discordChannels, teamId} tmView = do + let res = validateTeamDetails teamName teamHandle + case res of + Right _ -> do + rs <- case teamId of + Just tid -> do + _ <- dbtToEff $ ProjectMembers.updateTeam pid tid teamName teamDescription teamHandle teamMembers notifEmails slackChannels discordChannels + addSuccessToast "Team updated successfully" Nothing + html <- case tmView of + Just _ -> teamGetH pid teamHandle (Just "main-page") + _ -> manageTeamsGetH pid (Just "from_post") + return html + Nothing -> do + _ <- dbtToEff $ ProjectMembers.createTeam pid teamName teamDescription teamHandle teamMembers notifEmails slackChannels discordChannels + addSuccessToast "Team saved successfully" Nothing + html <- manageTeamsGetH pid (Just "from_post") + return html + return rs + Left e -> do + addErrorToast e Nothing + addReswap "" + addRespHeaders $ span_ [] $ toHtml e manageTeamsGetH :: Projects.ProjectId -> Maybe Text -> ATAuthCtx (RespHeaders (Html ())) @@ -594,18 +626,18 @@ manageTeamsPage pid projMembers channels discordChannels teams = do p_ [class_ "text-textWeak text-sm"] "Manage your project teams and their access" label_ [class_ "btn btn-primary btn-sm", Lucid.for_ "n-new-team-modal"] (faSprite_ "plus" "regular" "h-4 w-4 mr-2" >> "New Team") input_ [type_ "checkbox", id_ "n-new-team-modal", class_ "modal-toggle"] - teamModal pid Nothing whiteList channelWhiteList discordWhiteList + teamModal pid Nothing whiteList channelWhiteList discordWhiteList False div_ [class_ "flex items-center gap-4"] do label_ [class_ "input w-96"] do faSprite_ "magnifying-glass" "regular" "h-4 w-4 text-textWeak" - input_ [type_ "text", placeholder_ "Search teams...", class_ ""] + input_ [type_ "text", placeholder_ "Search teams...", class_ "", [__| on input show .team_filterble in #teams_list_container when its textContent.toLowerCase() contains my value.toLowerCase() |]] span_ [class_ "text-textWeak text-sm"] $ (show (V.length teams) <> " teams found") - div_ [class_ "mt-6 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-2 gap-4"] $ mapM_ (\t -> teamCard pid t whiteList channelWhiteList discordWhiteList) (V.toList teams) + div_ [class_ "mt-6 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-2 gap-4", id_ "teams_list_container"] $ mapM_ (\t -> teamCard pid t whiteList channelWhiteList discordWhiteList) (V.toList teams) teamCard :: Projects.ProjectId -> ProjectMembers.TeamVM -> Text -> Text -> Text -> Html () teamCard pid team whiteList channelWhiteList discordWhiteList = do - div_ [class_ "border border-strokeWeak rounded-xl shadow-sm hover:shadow-md transition-shadow duration-200 overflow-hidden"] do + div_ [class_ "border border-strokeWeak rounded-xl shadow-sm hover:shadow-md transition-shadow duration-200 overflow-hidden team_filterble"] do div_ [class_ "p-5 pb-3 flex flex-col gap-4"] do div_ [class_ "flex justify-between center"] do a_ [href_ $ "/p/" <> pid.toText <> "/manage_teams/" <> team.handle, class_ "flex items-center gap-4 min-w-0"] do @@ -616,7 +648,7 @@ teamCard pid team whiteList channelWhiteList discordWhiteList = do span_ [class_ "text-textWeak text-sm"] $ toHtml team.handle label_ [class_ "btn btn-ghost btn-sm", Lucid.for_ (team.handle <> "-new-team-modal")] "Edit" input_ [type_ "checkbox", id_ (team.handle <> "-new-team-modal"), class_ "modal-toggle"] - teamModal pid (Just team) whiteList channelWhiteList discordWhiteList + teamModal pid (Just team) whiteList channelWhiteList discordWhiteList False div_ [] do p_ [class_ "text-textWeak text-sm mt-1 line-clamp-2"] $ toHtml team.description div_ [class_ "flex items-center justify-between text-sm text-textWeak"] do @@ -645,8 +677,8 @@ teamCard pid team whiteList channelWhiteList discordWhiteList = do $ img_ [class_ "inline-block h-6 w-6 rounded-full ", src_ m.memberAvatar, alt_ "User avatar"] -teamGetH :: Projects.ProjectId -> Text -> ATAuthCtx (RespHeaders (Html ())) -teamGetH pid handle = do +teamGetH :: Projects.ProjectId -> Text -> Maybe Text -> ATAuthCtx (RespHeaders (Html ())) +teamGetH pid handle layoutM = do (sess, project) <- Sessions.sessionAndProject pid appCtx <- ask @AuthContext teamVm <- dbtToEff $ ProjectMembers.getTeamByHandle pid handle @@ -674,28 +706,36 @@ teamGetH pid handle = do , config = appCtx.config } case teamVm of - Just team -> addRespHeaders $ bodyWrapper bwconf $ teamPage pid team projMembers channels discordChannels + Just team -> case layoutM of + Just _ -> addRespHeaders $ teamPage pid team projMembers channels discordChannels + _ -> addRespHeaders $ bodyWrapper bwconf $ teamPage pid team projMembers channels discordChannels Nothing -> addRespHeaders $ bodyWrapper bwconf $ teamPageNF pid handle teamPage :: Projects.ProjectId -> ProjectMembers.TeamVM -> V.Vector ProjectMembers.ProjectMemberVM -> [Slack.SlackChannel] -> [Discord.DiscordChannel] -> Html () teamPage pid team projMembers slackChannels discordChannels = do + let whiteList = decodeUtf8 $ AE.encode $ (\x -> AE.object ["name" AE..= (x.first_name <> " " <> x.last_name), "email" AE..= x.email, "value" AE..= x.userId]) <$> projMembers + let channelWhiteList = decodeUtf8 $ AE.encode $ (\x -> AE.object ["name" AE..= ("#" <> x.channelName), "value" AE..= x.channelId]) <$> slackChannels + let discordWhiteList = decodeUtf8 $ AE.encode $ (\x -> AE.object ["name" AE..= ("#" <> x.channelName), "value" AE..= x.channelId]) <$> discordChannels section_ [id_ "main-content", class_ "w-full h-full"] do div_ [class_ "flex h-full border-t border-strokeWeak"] do div_ [class_ "p-4 w-4/12 space-y-6 mx-auto h-full overflow-y-auto"] do - div_ [class_ "flex items-center gap-3"] do - h2_ [class_ "text-xl font-semibold"] $ toHtml team.name - span_ [class_ "text-textWeak flex items-center gap-1 text-sm"] do - faSprite_ "copy" "regular" "w-3 h-3" - toHtml team.handle div_ [] do - p_ [class_ "text-textWeak text-sm"] $ toHtml team.description + div_ [class_ "flex items-center gap-3"] do + h2_ [class_ "text-xl font-semibold"] $ toHtml team.name + span_ [class_ "text-textWeak flex items-center gap-1 text-sm"] do + faSprite_ "copy" "regular" "w-3 h-3" + toHtml team.handle + p_ [class_ "text-textWeak mt-3 text-sm"] $ toHtml team.description div_ [class_ "rounded-lg p-2 border border-strokeWeak"] do - span_ [class_ "text-sm flex items-center gap-2 font-semibold py-2"] do - faSprite_ "users" "regular" "h-4 w-4" - toHtml $ "Members" - span_ [class_ "text-textWeak"] $ ("(" <> show (V.length team.members) <> ")") - + div_ [class_ "flex items-center justify-between"] do + span_ [class_ "text-sm flex items-center gap-2 font-semibold py-2"] do + faSprite_ "users" "regular" "h-4 w-4" + toHtml $ "Members" + span_ [class_ "text-textWeak"] $ ("(" <> show (V.length team.members) <> ")") + label_ [class_ "btn border border-strokeWeak btn-xs", Lucid.for_ $ team.handle <> "-new-team-modal"] (faSprite_ "plus" "regular" "h-4 w-4 mr-2" >> "Add") + input_ [type_ "checkbox", id_ $ team.handle <> "-new-team-modal", class_ "modal-toggle"] + teamModal pid (Just team) whiteList channelWhiteList discordWhiteList True div_ [] do forM_ team.members \m -> do div_ [class_ "flex flex-col gap-1 py-3 border-t border-strokeWeak"] do @@ -705,9 +745,12 @@ teamPage pid team projMembers slackChannels discordChannels = do span_ [class_ "text-textWeak text-xs"] $ toHtml m.memberEmail div_ [class_ "p-2 rounded-lg border border-strokeWeak"] do - span_ [class_ "text-sm flex items-center gap-2 py-2 font-semibold border-b border-strokeWeak"] do - faSprite_ "bell" "regular" "h-4 w-4" - "Notifications" + div_ [class_ "flex items-center justify-between"] do + span_ [class_ "text-sm flex items-center gap-2 py-2 font-semibold border-b border-strokeWeak"] do + faSprite_ "bell" "regular" "h-4 w-4" + "Notifications" + label_ [class_ "btn border border-strokeWeak btn-xs", Lucid.for_ $ team.handle <> "-new-team-modal"] (faSprite_ "plus" "regular" "h-4 w-4 mr-2" >> "Add") + div_ [] do div_ [class_ "flex flex-col gap-2 py-3 border-t border-strokeWeak"] do div_ [class_ "flex items-center text-sm gap-2 font-medium"] do @@ -735,8 +778,42 @@ teamPage pid team projMembers slackChannels discordChannels = do let tar = maybe e (.channelName) $ find (\x -> x.channelId == e) discordChannels span_ [] $ toHtml tar - div_ [class_ "h-full w-8/12 overflow-y-auto border-l p-2"] do - div_ [class_ "h-[1000px] w-full"] pass + div_ [class_ "h-full w-8/12 overflow-y-auto p-2"] do + div_ [class_ "h-[1000px] w-full p-4 space-y-6"] do + monitorsSection + dashboardsSection + + +monitorsSection :: Html () +monitorsSection = div_ [class_ "rounded-xl border border-strokeWeak shadow-sm overflow-x-hidden"] do + div_ [class_ "flex items-center justify-between w-full p-2"] do + h4_ [class_ "text-sm font-meidum"] "Monitors" + div_ [class_ "flex items-center gap-4"] do + label_ [class_ "input input-sm w-72"] do + faSprite_ "magnifying-glass" "regular" "h-4 w-4 text-textWeak" + input_ [type_ "text", placeholder_ "Search monitors...", class_ ""] + div_ [class_ "p-3 border-t border-strokeWeak w-full"] do + emptySectionState "No monitors are currently linked to this team" + + +dashboardsSection :: Html () +dashboardsSection = div_ [class_ "rounded-xl border border-strokeWeak overflow-x-hidden"] do + div_ [class_ "flex items-center justify-between w-full p-2"] do + h4_ [class_ "text-sm font-meidum"] "Dashboards" + div_ [class_ "flex items-center gap-4"] do + label_ [class_ "input input-sm w-72"] do + faSprite_ "magnifying-glass" "regular" "h-4 w-4 text-textWeak" + input_ [type_ "text", placeholder_ "Search dashboards...", class_ ""] + div_ [class_ "p-3 border-t w-full border-strokeWeak"] do + emptySectionState "No dashboards are currently linked to this team" + + +emptySectionState :: Text -> Html () +emptySectionState message = + div_ [class_ "flex flex-col items-center justify-center py-10 text-center text-textWeak gap-3"] do + faSprite_ "empty" "regular" "h-8 w-8 text-textWeak" + div_ [class_ "text-sm"] $ toHtml message + button_ [class_ "btn btn-primary btn-sm"] "Create dashboard" teamPageNF :: Projects.ProjectId -> Text -> Html () @@ -1315,8 +1392,8 @@ data NotificationChannel -- Main Modal Component -teamModal :: Projects.ProjectId -> Maybe ProjectMembers.TeamVM -> Text -> Text -> Text -> Html () -teamModal pid team whiteList channelWhiteList discordWhiteList = do +teamModal :: Projects.ProjectId -> Maybe ProjectMembers.TeamVM -> Text -> Text -> Text -> Bool -> Html () +teamModal pid team whiteList channelWhiteList discordWhiteList isInTeamView = do let name = maybe "" (.name) team let handle = maybe "" (.handle) team let description = maybe "" (.description) team @@ -1330,7 +1407,7 @@ teamModal pid team whiteList channelWhiteList discordWhiteList = do div_ [class_ "modal", role_ "dialog", style_ "--color-base-100: var(--color-bgOverlay)"] $ do div_ [class_ "modal-box"] $ do form_ - [ hxPost_ "" + [ hxPost_ $ "/p/" <> pid.toText <> "/manage_teams?" <> (if isInTeamView then "teamView=true" else "") , hxExt_ "json-enc" , hxVals_ [text|js:{...getTagValues(`$prefix`)}|] , hxTarget_ "#main-content" @@ -1480,43 +1557,132 @@ window[`$prefix-membersTagify`].on("change", (e) => { |] --- Team Details Section teamDetailsSection :: Text -> Text -> Text -> Html () teamDetailsSection name handle description = do + let prefix = if T.null handle then "n" else handle div_ [class_ "space-y-4"] $ do - -- Team Name Field div_ [class_ "flex items-center w-full gap-2 justify-between"] do div_ [class_ "flex flex-col w-full gap-2"] $ do label_ [class_ "text-sm font-medium ", Lucid.for_ "team-name"] "Team Name" input_ [ class_ "input w-full" , type_ "text" - , id_ "team-name" + , id_ $ prefix <> "-team-name" , name_ "teamName" , placeholder_ "e.g. Backend Team" , value_ name ] + span_ [id_ $ prefix <> "-team-name-error", class_ "text-xs text-red-500 h-4"] "" div_ [class_ "flex flex-col gap-2 w-full"] $ do label_ [class_ "text-sm font-medium ", Lucid.for_ "team-handle"] "Team Handle" input_ [ class_ "input w-full" , type_ "text" - , id_ "team-handle" + , id_ $ prefix <> "-team-handle" , name_ "teamHandle" , placeholder_ "e.g. backend-team" , value_ handle ] - -- Description Field + span_ [id_ $ prefix <> "-team-handle-error", class_ "text-xs text-red-500 h-4"] "" div_ [class_ "flex flex-col gap-2"] $ do label_ [class_ "text-sm font-medium ", Lucid.for_ "team-description"] "Description" textarea_ [ class_ "w-full p-2 min-h-[80px] input focus:outline-none focus:ring-2 focus:ring-ring resize-none" - , id_ "team-description" + , id_ $ prefix <> "-team-description" , name_ "teamDescription" , placeholder_ "What does this team do?" ] $ toHtml description + script_ + [text| + +document.addEventListener("DOMContentLoaded", () => { + const nameInput = document.getElementById("$prefix-team-name"); + const handleInput = document.getElementById("$prefix-team-handle"); + + const nameError = document.getElementById("$prefix-team-name-error"); + const handleError = document.getElementById("$prefix-team-handle-error"); + + let handleManuallyEdited = false; + + handleInput.addEventListener("input", () => { + handleManuallyEdited = true; + }); + + nameInput.addEventListener("input", () => { + if (!handleManuallyEdited) { + const val = nameInput.value.toLowerCase().trim(); + const generated = val + .replace(/[^a-z0-9\s-]/g, "") // remove invalid chars + .replace(/\s+/g, "-") // spaces → hyphens + .replace(/-{2,}/g, "-") // collapse multiple hyphens + .replace(/^-+|-+$/g, ""); // trim hyphens + + handleInput.value = generated; + showError(handleInput, handleError, validators.handle()); + } + showError(nameInput, nameError, validators.name()); + }); + + const validators = { + name() { + const val = nameInput.value.trim(); + if (!val) return "Team name is required"; + if (val.length < 3) return "Team name must be at least 3 characters"; + if (!/^[\w\s-]+$/.test(val)) return "Invalid characters in team name"; + return ""; + }, + + handle() { + const val = handleInput.value.trim(); + if (!val) return "Handle is required"; + if (!/^[a-z][a-z0-9-]*$/.test(val)) + return "Handle must be lowercase, no spaces, and start with a letter"; + return ""; + }, + }; + + function showError(input, elem, msg) { + if (msg) { + input.classList.add("border-red-500"); + elem.textContent = msg; + } else { + input.classList.remove("border-red-500"); + elem.textContent = ""; + } + } + + nameInput.addEventListener("input", () => + showError(nameInput, nameError, validators.name()) + ); + handleInput.addEventListener("input", () => + showError(handleInput, handleError, validators.handle()) + ); + + const form = nameInput.closest("form"); + if (form) { + form.addEventListener("submit", (e) => { + const nameErr = validators.name(); + const handleErr = validators.handle(); + + showError(nameInput, nameError, nameErr); + showError(handleInput, handleError, handleErr); + + const firstInvalid = + nameErr ? nameInput : + handleErr ? handleInput : null; + + if (firstInvalid) { + e.preventDefault(); + firstInvalid.scrollIntoView({ behavior: "smooth", block: "center" }); + firstInvalid.focus(); + return false + } + }); + } +}); +|] -- Notification Channels Section diff --git a/src/System/Types.hs b/src/System/Types.hs index bace609ff..c9e607c29 100644 --- a/src/System/Types.hs +++ b/src/System/Types.hs @@ -14,6 +14,7 @@ module System.Types ( addSuccessToast, addErrorToast, addWidgetJSON, + addReswap, HXRedirectDest, XWidgetJSON, TriggerEvents, @@ -74,6 +75,7 @@ newtype WidgetJSON = WidgetJSON {unWidgetJSON :: Text} type XWidgetJSON = Maybe WidgetJSON +type HXReswap = Maybe Text type CommonWebEffects = @@ -206,6 +208,7 @@ type RespHeaders = '[ HXTriggerAfterSettle , HXRedirect , Header "X-Widget-JSON" Text + , Header "HX-Reswap" Text ] @@ -214,9 +217,11 @@ addRespHeaders resp = do triggerEvents <- State.get @TriggerEvents redirectDest <- State.get @HXRedirectDest widgetJSON <- State.get @XWidgetJSON + reswap <- State.get @HXReswap pure $ addHeader (decodeUtf8 $ AE.encode triggerEvents) $ maybe noHeader addHeader redirectDest + $ maybe noHeader addHeader reswap $ maybe noHeader (\w -> addHeader w.unWidgetJSON) widgetJSON resp @@ -241,6 +246,10 @@ addSuccessToast :: State.State TriggerEvents :> es => Text -> Maybe Text -> Eff addSuccessToast = addToast "success" +addReswap :: State.State HXReswap :> es => Text -> Eff es () +addReswap x = State.modify $ \_ -> Just x + + addErrorToast :: (IOE :> es, Log :> es, State.State TriggerEvents :> es) => Text -> Maybe Text -> Eff es () addErrorToast msg msg2 = do Logging.logAttention_ $ "ERROR: " <> msg <> " => " <> maybeToMonoid msg2 diff --git a/src/Web/Routes.hs b/src/Web/Routes.hs index 723b3c0c8..bb9372d52 100644 --- a/src/Web/Routes.hs +++ b/src/Web/Routes.hs @@ -307,8 +307,8 @@ data ProjectsRoutes' mode = ProjectsRoutes' membersManageGet :: mode :- "p" :> Capture "projectId" Projects.ProjectId :> "manage_members" :> Get '[HTML] (RespHeaders ManageMembers.ManageMembers) , membersManagePost :: mode :- "p" :> Capture "projectId" Projects.ProjectId :> "manage_members" :> QPT "onboarding" :> ReqBody '[FormUrlEncoded] ManageMembers.ManageMembersForm :> Post '[HTML] (RespHeaders ManageMembers.ManageMembers) , teamsManageGet :: mode :- "p" :> Capture "projectId" Projects.ProjectId :> "manage_teams" :> QPT "what" :> Get '[HTML] (RespHeaders (Html ())) - , teamsManagePost :: mode :- "p" :> Capture "projectId" Projects.ProjectId :> "manage_teams" :> ReqBody '[JSON] ManageMembers.TeamForm :> Post '[HTML] (RespHeaders (Html ())) - , teamGet :: mode :- "p" :> Capture "projectId" Projects.ProjectId :> "manage_teams" :> Capture "teamHandle" Text :> Get '[HTML] (RespHeaders (Html ())) + , teamsManagePost :: mode :- "p" :> Capture "projectId" Projects.ProjectId :> "manage_teams" :> ReqBody '[JSON] ManageMembers.TeamForm :> QPT "teamView" :> Post '[HTML] (RespHeaders (Html ())) + , teamGet :: mode :- "p" :> Capture "projectId" Projects.ProjectId :> "manage_teams" :> Capture "teamHandle" Text :> QPT "layout" :> Get '[HTML] (RespHeaders (Html ())) , manageSubscriptionGet :: mode :- "p" :> Capture "projectId" Projects.ProjectId :> "manage_subscription" :> Get '[HTML] (RespHeaders (Html ())) , -- Notifications notificationsUpdateChannelPost :: mode :- "p" :> Capture "projectId" Projects.ProjectId :> "notifications-channels" :> ReqBody '[FormUrlEncoded] Integrations.NotifListForm :> Post '[HTML] (RespHeaders Integrations.NotificationsUpdatePost) diff --git a/static/public/assets/deps/htmx/json-enc-2.js b/static/public/assets/deps/htmx/json-enc-2.js index 235088a59..03f59ad3d 100644 --- a/static/public/assets/deps/htmx/json-enc-2.js +++ b/static/public/assets/deps/htmx/json-enc-2.js @@ -32,7 +32,7 @@ } }) - return JSON.stringify({ object, ...vals }) + return JSON.stringify({ ...object, ...vals }) }, }) })() From 66b5fe25715d4bfbabd800b6e77316eae25dee5b Mon Sep 17 00:00:00 2001 From: Yussif Mohammed Date: Mon, 1 Dec 2025 17:15:04 +0000 Subject: [PATCH 08/56] tiny details improvments --- src/Pages/Projects.hs | 84 +++++++++++-------- .../assets/css/thirdparty/tagify.min.css | 6 +- 2 files changed, 54 insertions(+), 36 deletions(-) diff --git a/src/Pages/Projects.hs b/src/Pages/Projects.hs index c8dd47fc8..939d07ed7 100644 --- a/src/Pages/Projects.hs +++ b/src/Pages/Projects.hs @@ -657,7 +657,7 @@ teamCard pid team whiteList channelWhiteList discordWhiteList = do faSprite_ "users" "regular" "h-3.5 w-3.5" span_ [] $ toHtml $ show $ V.length team.members div_ [class_ "flex items-center gap-1", term "data-tippy-content" "Dashboards"] do - faSprite_ "dashboard" "regular" "h-3 w-3" + faSprite_ "chart-area" "regular" "h-3 w-3" span_ [] $ toHtml $ show $ V.length team.members div_ [class_ "flex items-center gap-1", term "data-tippy-content" "Monitors"] do faSprite_ "information" "regular" "h-3.5 w-3.5" @@ -670,7 +670,7 @@ teamCard pid team whiteList channelWhiteList discordWhiteList = do when (not $ V.null team.notify_emails) do faSprite_ "envelope" "regular" "h-3.5 w-3.5" div_ [class_ "flex justify-between items-center text-textWeak text-xs mt-2"] do - toHtml $ "Created " <> (toText $ formatTime defaultTimeLocale "%Y-%m-%dT%H:%M:%S%6QZ" team.created_at) + toHtml $ "Created " <> (toText $ formatTime defaultTimeLocale "%Y-%m-%dT%H:%M:%S" team.created_at) div_ [class_ "inline-block flex -space-x-2"] do forM_ team.members $ \m -> do div_ [class_ "inline-block mx-0.5", term "data-tippy-content" (m.memberName)] @@ -727,39 +727,38 @@ teamPage pid team projMembers slackChannels discordChannels = do faSprite_ "copy" "regular" "w-3 h-3" toHtml team.handle p_ [class_ "text-textWeak mt-3 text-sm"] $ toHtml team.description - div_ [class_ "rounded-lg p-2 border border-strokeWeak"] do - div_ [class_ "flex items-center justify-between"] do - span_ [class_ "text-sm flex items-center gap-2 font-semibold py-2"] do - faSprite_ "users" "regular" "h-4 w-4" + div_ [class_ "rounded-lg p-4 border border-strokeWeak"] do + div_ [class_ "flex items-center justify-between mb-2"] do + span_ [class_ "flex items-center gap-2 font-semibold py-2"] do + faSprite_ "users" "regular" "h-5 w-5" toHtml $ "Members" span_ [class_ "text-textWeak"] $ ("(" <> show (V.length team.members) <> ")") - label_ [class_ "btn border border-strokeWeak btn-xs", Lucid.for_ $ team.handle <> "-new-team-modal"] (faSprite_ "plus" "regular" "h-4 w-4 mr-2" >> "Add") + label_ [class_ "btn btn-outline border border-strokeWeak btn-xs", Lucid.for_ $ team.handle <> "-new-team-modal"] (faSprite_ "plus" "regular" "h-3 w-3 mr-1" >> "Add") input_ [type_ "checkbox", id_ $ team.handle <> "-new-team-modal", class_ "modal-toggle"] teamModal pid (Just team) whiteList channelWhiteList discordWhiteList True div_ [] do forM_ team.members \m -> do - div_ [class_ "flex flex-col gap-1 py-3 border-t border-strokeWeak"] do + div_ [class_ "flex flex-col gap-1 py-3 "] do div_ [class_ "flex gap-2 text-sm"] do img_ [src_ m.memberAvatar, class_ "w-5 h-5 rounded-full border border-strokeWeak"] span_ [] $ toHtml m.memberName span_ [class_ "text-textWeak text-xs"] $ toHtml m.memberEmail - div_ [class_ "p-2 rounded-lg border border-strokeWeak"] do - div_ [class_ "flex items-center justify-between"] do - span_ [class_ "text-sm flex items-center gap-2 py-2 font-semibold border-b border-strokeWeak"] do - faSprite_ "bell" "regular" "h-4 w-4" + div_ [class_ "p-4 rounded-lg border border-strokeWeak"] do + div_ [class_ "flex items-center justify-between mb-2"] do + span_ [class_ "flex items-center gap-2 py-2 font-semibold"] do + faSprite_ "bell" "regular" "h-5 w-5" "Notifications" - label_ [class_ "btn border border-strokeWeak btn-xs", Lucid.for_ $ team.handle <> "-new-team-modal"] (faSprite_ "plus" "regular" "h-4 w-4 mr-2" >> "Add") - + label_ [class_ "btn btn-outline border border-strokeWeak btn-xs", Lucid.for_ $ team.handle <> "-new-team-modal"] (faSprite_ "plus" "regular" "h-3 w-3 mr-1" >> "Add") div_ [] do - div_ [class_ "flex flex-col gap-2 py-3 border-t border-strokeWeak"] do + div_ [class_ "flex flex-col gap-2 py-3"] do div_ [class_ "flex items-center text-sm gap-2 font-medium"] do faSprite_ "envelope" "regular" "h-4 w-4" "Email addresses" div_ [class_ "flex items-center gap-2 text-xs text-textWeak"] do when (V.null team.notify_emails) $ span_ [] "No emails added" forM_ team.notify_emails \e -> span_ [] $ toHtml e - div_ [class_ "flex flex-col gap-2 py-3 border-t border-strokeWeak"] do + div_ [class_ "flex flex-col gap-2 py-3"] do div_ [class_ "flex items-center text-sm gap-2 font-medium"] do faSprite_ "slack" "solid" "h-4 w-4" "Slack channels" @@ -768,7 +767,7 @@ teamPage pid team projMembers slackChannels discordChannels = do forM_ team.slack_channels \e -> do let tar = maybe e (.channelName) $ find (\x -> x.channelId == e) slackChannels span_ [] $ toHtml tar - div_ [class_ "flex flex-col gap-2 py-3 border-t border-strokeWeak"] do + div_ [class_ "flex flex-col gap-2 py-3"] do div_ [class_ "flex items-center text-sm gap-2 font-medium"] do faSprite_ "discord" "solid" "h-4 w-4" "Discord channels" @@ -778,32 +777,50 @@ teamPage pid team projMembers slackChannels discordChannels = do let tar = maybe e (.channelName) $ find (\x -> x.channelId == e) discordChannels span_ [] $ toHtml tar - div_ [class_ "h-full w-8/12 overflow-y-auto p-2"] do - div_ [class_ "h-[1000px] w-full p-4 space-y-6"] do + div_ [class_ "h-full w-8/12 overflow-y-auto p-4"] do + div_ [class_ "h-[1000px] w-full space-y-6"] do monitorsSection dashboardsSection monitorsSection :: Html () monitorsSection = div_ [class_ "rounded-xl border border-strokeWeak shadow-sm overflow-x-hidden"] do - div_ [class_ "flex items-center justify-between w-full p-2"] do - h4_ [class_ "text-sm font-meidum"] "Monitors" - div_ [class_ "flex items-center gap-4"] do - label_ [class_ "input input-sm w-72"] do - faSprite_ "magnifying-glass" "regular" "h-4 w-4 text-textWeak" - input_ [type_ "text", placeholder_ "Search monitors...", class_ ""] + div_ + [ class_ "flex items-center justify-between w-full p-2 hover:bg-fillWeaker cursor-pointer" + , [__|on click toggle .hidden on the next
+ then toggle .rotate-270 on the first