diff --git a/src/UnisonShare/Account.elm b/src/UnisonShare/Account.elm index 30716c28..a415d5db 100644 --- a/src/UnisonShare/Account.elm +++ b/src/UnisonShare/Account.elm @@ -1,12 +1,14 @@ module UnisonShare.Account exposing (..) -import Json.Decode as Decode exposing (field, maybe, string) +import Json.Decode as Decode exposing (string) +import Json.Decode.Pipeline exposing (optional, required) import Lib.Decode.Helpers exposing (url) import Lib.UserHandle as UserHandle exposing (UserHandle) import UI.Avatar as Avatar exposing (Avatar) import UI.Icon as Icon import UnisonShare.Project.ProjectRef as ProjectRef exposing (ProjectRef) import UnisonShare.Tour as Tour exposing (Tour) +import UnisonShare.UnisonPlan as UnisonPlan exposing (UnisonPlan) import UnisonShare.User exposing (UserSummary) import Url exposing (Url) @@ -21,6 +23,8 @@ type alias Account a = , organizationMemberships : List OrganizationMembership , isSuperAdmin : Bool , primaryEmail : String + , plan : UnisonPlan + , hasUnreadNotifications : Bool } @@ -90,22 +94,26 @@ isProjectOwner projectRef account = decodeSummary : Decode.Decoder AccountSummary decodeSummary = let - makeSummary handle name_ avatarUrl completedTours organizationMemberships isSuperAdmin primaryEmail = + makeSummary handle name_ avatarUrl completedTours organizationMemberships isSuperAdmin primaryEmail plan hasUnreadNotifications = { handle = handle , name = name_ , avatarUrl = avatarUrl , pronouns = Nothing , completedTours = Maybe.withDefault [] completedTours , organizationMemberships = organizationMemberships - , isSuperAdmin = Maybe.withDefault False isSuperAdmin + , isSuperAdmin = isSuperAdmin , primaryEmail = primaryEmail + , plan = plan + , hasUnreadNotifications = hasUnreadNotifications } in - Decode.map7 makeSummary - (field "handle" UserHandle.decodeUnprefixed) - (maybe (field "name" string)) - (maybe (field "avatarUrl" url)) - (maybe (field "completedTours" (Decode.list Tour.decode))) - (field "organizationMemberships" (Decode.list (Decode.map OrganizationMembership UserHandle.decodeUnprefixed))) - (maybe (field "isSuperadmin" Decode.bool)) - (field "primaryEmail" string) + Decode.succeed makeSummary + |> required "handle" UserHandle.decodeUnprefixed + |> optional "name" (Decode.map Just string) Nothing + |> optional "avatarUrl" (Decode.map Just url) Nothing + |> optional "completedTours" (Decode.map Just (Decode.list Tour.decode)) Nothing + |> required "organizationMemberships" (Decode.list (Decode.map OrganizationMembership UserHandle.decodeUnprefixed)) + |> optional "isSuperadmin" Decode.bool False + |> required "primaryEmail" string + |> required "planTier" UnisonPlan.decode + |> required "hasUnreadNotifications" Decode.bool diff --git a/src/UnisonShare/Project.elm b/src/UnisonShare/Project.elm index da9e30da..4a37a762 100644 --- a/src/UnisonShare/Project.elm +++ b/src/UnisonShare/Project.elm @@ -57,6 +57,7 @@ type alias ProjectDetails = , permissions : List ProjectPermission , createdAt : DateTime , updatedAt : DateTime + , isPremiumProject : Bool } @@ -216,7 +217,7 @@ decodeIsFaved = decodeDetails : Decode.Decoder ProjectDetails decodeDetails = let - makeProjectDetails handle_ slug_ summary tags visibility numFavs numActiveContributions numOpenTickets releaseDownloads isFaved_ latestVersion defaultBranch permissions createdAt updatedAt = + makeProjectDetails handle_ slug_ summary tags visibility numFavs numActiveContributions numOpenTickets releaseDownloads isFaved_ latestVersion defaultBranch permissions createdAt updatedAt isPremiumProject = let ref_ = ProjectRef.projectRef handle_ slug_ @@ -235,6 +236,7 @@ decodeDetails = , permissions = permissions , createdAt = createdAt , updatedAt = updatedAt + , isPremiumProject = isPremiumProject } in Decode.succeed makeProjectDetails @@ -253,6 +255,7 @@ decodeDetails = |> required "permissions" ProjectPermission.decodeList |> required "createdAt" DateTime.decode |> required "updatedAt" DateTime.decode + |> optional "isPremiumProject" Decode.bool False decode : Decode.Decoder (Project {}) diff --git a/src/UnisonShare/UnisonPlan.elm b/src/UnisonShare/UnisonPlan.elm new file mode 100644 index 00000000..953d8138 --- /dev/null +++ b/src/UnisonShare/UnisonPlan.elm @@ -0,0 +1,43 @@ +module UnisonShare.UnisonPlan exposing (UnisonPlan(..), decode, fromString, toString) + +import Json.Decode as Decode + + +type UnisonPlan + = Free + | Starter + | Pro + + +fromString : String -> UnisonPlan +fromString s = + case s of + "Free" -> + Free + + "Starter" -> + Starter + + "Pro" -> + Pro + + _ -> + Free + + +toString : UnisonPlan -> String +toString p = + case p of + Free -> + "Free" + + Starter -> + "Starter" + + Pro -> + "Pro" + + +decode : Decode.Decoder UnisonPlan +decode = + Decode.map fromString Decode.string diff --git a/tests/UnisonShare/ProjectTests.elm b/tests/UnisonShare/ProjectTests.elm index 320a6f91..2a913714 100644 --- a/tests/UnisonShare/ProjectTests.elm +++ b/tests/UnisonShare/ProjectTests.elm @@ -104,4 +104,5 @@ projectDetails isFaved numFavs = , permissions = [] , createdAt = DateTime.fromPosix (Time.millisToPosix 1) , updatedAt = DateTime.fromPosix (Time.millisToPosix 1) + , isPremiumProject = False } diff --git a/tests/e2e/TestHelpers/Data.ts b/tests/e2e/TestHelpers/Data.ts index 5bf3152f..b9ef3765 100644 --- a/tests/e2e/TestHelpers/Data.ts +++ b/tests/e2e/TestHelpers/Data.ts @@ -8,6 +8,8 @@ function account(handle: string) { isSuperadmin: false, organizationMemberships: [], primaryEmail: faker.internet.email(), + hasUnreadNotifications: false, + planTier: "Free", }; } @@ -120,6 +122,7 @@ function project(ref?: string) { tags: [], updatedAt: faker.date.past(), visibility: "public", + isPremiumProject: false, }; }