Skip to content

Commit

Permalink
Use posthog in onboarding survey and update custom attributes #4343
Browse files Browse the repository at this point in the history
ref DEV-1367
  • Loading branch information
tung2744 authored Jun 25, 2024
2 parents 7974693 + 732062f commit bec6454
Show file tree
Hide file tree
Showing 15 changed files with 359 additions and 175 deletions.
19 changes: 0 additions & 19 deletions pkg/portal/graphql/app_mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/authgear/authgear-server/pkg/lib/config/configsource"
"github.com/authgear/authgear-server/pkg/lib/tutorial"
"github.com/authgear/authgear-server/pkg/portal/appresource"
"github.com/authgear/authgear-server/pkg/portal/model"
"github.com/authgear/authgear-server/pkg/portal/session"
"github.com/authgear/authgear-server/pkg/util/graphqlutil"
)
Expand Down Expand Up @@ -361,10 +360,6 @@ var createAppInput = graphql.NewInputObject(graphql.InputObjectConfig{
Type: graphql.NewNonNull(graphql.String),
Description: "ID of the new app.",
},
"phoneNumber": &graphql.InputObjectFieldConfig{
Type: graphql.String,
Description: "Phone number of the new app.",
},
},
})

Expand All @@ -390,7 +385,6 @@ var _ = registerMutationField(
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
input := p.Args["input"].(map[string]interface{})
appID := input["id"].(string)
phoneNumber := input["phoneNumber"].(string)

gqlCtx := GQLContext(p.Context)

Expand All @@ -407,19 +401,6 @@ var _ = registerMutationField(
return nil, err
}

if phoneNumber != "" {
entry := model.OnboardEntry{
PhoneNumber: phoneNumber,
}
err := gqlCtx.OnboardService.SubmitOnboardEntry(
entry,
actorID,
)
if err != nil {
return nil, err
}
}

app, err := gqlCtx.AppService.Create(actorID, appID)
if err != nil {
return nil, err
Expand Down
56 changes: 56 additions & 0 deletions pkg/portal/graphql/survey_mutation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package graphql

import (
"github.com/graphql-go/graphql"

"github.com/authgear/authgear-server/pkg/portal/model"
"github.com/authgear/authgear-server/pkg/portal/session"
)

var saveOnboardingSurveyInput = graphql.NewInputObject(graphql.InputObjectConfig{
Name: "SaveOnboardingSurveyInput",
Fields: graphql.InputObjectConfigFieldMap{
"surveyJSON": &graphql.InputObjectFieldConfig{
Type: graphql.NewNonNull(graphql.String),
Description: "Onboarding survey result JSON.",
},
},
})

var _ = registerMutationField(
"saveOnboardingSurvey",
&graphql.Field{
Description: "Updates the current user's custom attribute with 'survey' key",
Type: graphql.Boolean,
Args: graphql.FieldConfigArgument{
"input": &graphql.ArgumentConfig{
Type: graphql.NewNonNull(saveOnboardingSurveyInput),
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
input := p.Args["input"].(map[string]interface{})
surveyJSON := input["surveyJSON"].(string)
gqlCtx := GQLContext(p.Context)

// Access Control: authenicated user.
sessionInfo := session.GetValidSessionInfo(p.Context)
if sessionInfo == nil {
return nil, Unauthenticated.New("only authenticated users can fill onboarding survey")
}
actorID := sessionInfo.UserID

entry := model.OnboardEntry{
SurveyJSON: surveyJSON,
}
err := gqlCtx.OnboardService.SubmitOnboardEntry(
entry,
actorID,
)
if err != nil {
return nil, err
}

return nil, nil
},
},
)
2 changes: 1 addition & 1 deletion pkg/portal/model/onboard.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package model

type OnboardEntry struct {
PhoneNumber string `json:"onboarding_survey_phone_number"`
SurveyJSON string `json:"onboarding_survey_json"`
}
Loading

0 comments on commit bec6454

Please sign in to comment.