11module UnisonShare.Account exposing (..)
22
3- import Json.Decode as Decode exposing (field , maybe , string )
3+ import Json.Decode as Decode exposing (string )
4+ import Json.Decode.Pipeline exposing (optional , required )
45import Lib.Decode.Helpers exposing (url )
56import Lib.UserHandle as UserHandle exposing (UserHandle )
67import UI.Avatar as Avatar exposing (Avatar )
78import UI.Icon as Icon
89import UnisonShare.Project.ProjectRef as ProjectRef exposing (ProjectRef )
910import UnisonShare.Tour as Tour exposing (Tour )
11+ import UnisonShare.UnisonPlan as UnisonPlan exposing (UnisonPlan )
1012import UnisonShare.User exposing (UserSummary )
1113import Url exposing (Url )
1214
@@ -21,6 +23,8 @@ type alias Account a =
2123 , organizationMemberships : List OrganizationMembership
2224 , isSuperAdmin : Bool
2325 , primaryEmail : String
26+ , plan : UnisonPlan
27+ , hasUnreadNotifications : Bool
2428 }
2529
2630
@@ -90,22 +94,26 @@ isProjectOwner projectRef account =
9094decodeSummary : Decode .Decoder AccountSummary
9195decodeSummary =
9296 let
93- makeSummary handle name_ avatarUrl completedTours organizationMemberships isSuperAdmin primaryEmail =
97+ makeSummary handle name_ avatarUrl completedTours organizationMemberships isSuperAdmin primaryEmail plan hasUnreadNotifications =
9498 { handle = handle
9599 , name = name_
96100 , avatarUrl = avatarUrl
97101 , pronouns = Nothing
98102 , completedTours = Maybe . withDefault [] completedTours
99103 , organizationMemberships = organizationMemberships
100- , isSuperAdmin = Maybe . withDefault False isSuperAdmin
104+ , isSuperAdmin = isSuperAdmin
101105 , primaryEmail = primaryEmail
106+ , plan = plan
107+ , hasUnreadNotifications = hasUnreadNotifications
102108 }
103109 in
104- Decode . map7 makeSummary
105- ( field " handle" UserHandle . decodeUnprefixed)
106- ( maybe ( field " name" string))
107- ( maybe ( field " avatarUrl" url))
108- ( maybe ( field " completedTours" ( Decode . list Tour . decode)))
109- ( field " organizationMemberships" ( Decode . list ( Decode . map OrganizationMembership UserHandle . decodeUnprefixed)))
110- ( maybe ( field " isSuperadmin" Decode . bool))
111- ( field " primaryEmail" string)
110+ Decode . succeed makeSummary
111+ |> required " handle" UserHandle . decodeUnprefixed
112+ |> optional " name" ( Decode . map Just string) Nothing
113+ |> optional " avatarUrl" ( Decode . map Just url) Nothing
114+ |> optional " completedTours" ( Decode . map Just ( Decode . list Tour . decode)) Nothing
115+ |> required " organizationMemberships" ( Decode . list ( Decode . map OrganizationMembership UserHandle . decodeUnprefixed))
116+ |> optional " isSuperadmin" Decode . bool False
117+ |> required " primaryEmail" string
118+ |> required " planTier" UnisonPlan . decode
119+ |> required " hasUnreadNotifications" Decode . bool
0 commit comments