Skip to content

Commit cd2e6bc

Browse files
authored
Merge pull request #86 from unisoncomputing/account-and-project-fields
Account and Project decoding new fields
2 parents 47ff801 + 532fa53 commit cd2e6bc

File tree

5 files changed

+70
-12
lines changed

5 files changed

+70
-12
lines changed

src/UnisonShare/Account.elm

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
module 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)
45
import Lib.Decode.Helpers exposing (url)
56
import Lib.UserHandle as UserHandle exposing (UserHandle)
67
import UI.Avatar as Avatar exposing (Avatar)
78
import UI.Icon as Icon
89
import UnisonShare.Project.ProjectRef as ProjectRef exposing (ProjectRef)
910
import UnisonShare.Tour as Tour exposing (Tour)
11+
import UnisonShare.UnisonPlan as UnisonPlan exposing (UnisonPlan)
1012
import UnisonShare.User exposing (UserSummary)
1113
import 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 =
9094
decodeSummary : Decode.Decoder AccountSummary
9195
decodeSummary =
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

src/UnisonShare/Project.elm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type alias ProjectDetails =
5757
, permissions : List ProjectPermission
5858
, createdAt : DateTime
5959
, updatedAt : DateTime
60+
, isPremiumProject : Bool
6061
}
6162

6263

@@ -216,7 +217,7 @@ decodeIsFaved =
216217
decodeDetails : Decode.Decoder ProjectDetails
217218
decodeDetails =
218219
let
219-
makeProjectDetails handle_ slug_ summary tags visibility numFavs numActiveContributions numOpenTickets releaseDownloads isFaved_ latestVersion defaultBranch permissions createdAt updatedAt =
220+
makeProjectDetails handle_ slug_ summary tags visibility numFavs numActiveContributions numOpenTickets releaseDownloads isFaved_ latestVersion defaultBranch permissions createdAt updatedAt isPremiumProject =
220221
let
221222
ref_ =
222223
ProjectRef.projectRef handle_ slug_
@@ -235,6 +236,7 @@ decodeDetails =
235236
, permissions = permissions
236237
, createdAt = createdAt
237238
, updatedAt = updatedAt
239+
, isPremiumProject = isPremiumProject
238240
}
239241
in
240242
Decode.succeed makeProjectDetails
@@ -253,6 +255,7 @@ decodeDetails =
253255
|> required "permissions" ProjectPermission.decodeList
254256
|> required "createdAt" DateTime.decode
255257
|> required "updatedAt" DateTime.decode
258+
|> optional "isPremiumProject" Decode.bool False
256259

257260

258261
decode : Decode.Decoder (Project {})

src/UnisonShare/UnisonPlan.elm

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module UnisonShare.UnisonPlan exposing (UnisonPlan(..), decode, fromString, toString)
2+
3+
import Json.Decode as Decode
4+
5+
6+
type UnisonPlan
7+
= Free
8+
| Starter
9+
| Pro
10+
11+
12+
fromString : String -> UnisonPlan
13+
fromString s =
14+
case s of
15+
"Free" ->
16+
Free
17+
18+
"Starter" ->
19+
Starter
20+
21+
"Pro" ->
22+
Pro
23+
24+
_ ->
25+
Free
26+
27+
28+
toString : UnisonPlan -> String
29+
toString p =
30+
case p of
31+
Free ->
32+
"Free"
33+
34+
Starter ->
35+
"Starter"
36+
37+
Pro ->
38+
"Pro"
39+
40+
41+
decode : Decode.Decoder UnisonPlan
42+
decode =
43+
Decode.map fromString Decode.string

tests/UnisonShare/ProjectTests.elm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,5 @@ projectDetails isFaved numFavs =
104104
, permissions = []
105105
, createdAt = DateTime.fromPosix (Time.millisToPosix 1)
106106
, updatedAt = DateTime.fromPosix (Time.millisToPosix 1)
107+
, isPremiumProject = False
107108
}

tests/e2e/TestHelpers/Data.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ function account(handle: string) {
88
isSuperadmin: false,
99
organizationMemberships: [],
1010
primaryEmail: faker.internet.email(),
11+
hasUnreadNotifications: false,
12+
planTier: "Free",
1113
};
1214
}
1315

@@ -120,6 +122,7 @@ function project(ref?: string) {
120122
tags: [],
121123
updatedAt: faker.date.past(),
122124
visibility: "public",
125+
isPremiumProject: false,
123126
};
124127
}
125128

0 commit comments

Comments
 (0)