Skip to content

Commit 6fbb54a

Browse files
committed
monetization fixes
1 parent 1c63584 commit 6fbb54a

File tree

9 files changed

+39
-25
lines changed

9 files changed

+39
-25
lines changed

kite-service/cmd/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func serverStartCMD(c *cli.Context) error {
9595
billingPlans[i] = model.Plan(plan)
9696
}
9797

98-
planManager := plan.NewPlanManager(pg, pg, billingPlans, plan.PlanManagerConfig{
98+
planManager := plan.NewPlanManager(pg, pg, pg, billingPlans, plan.PlanManagerConfig{
9999
DiscordBotToken: cfg.Discord.BotToken,
100100
DiscordGuildID: cfg.Discord.GuildID,
101101
})

kite-service/internal/api/handler/billing/feature.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,3 @@ func (h *BillingHandler) HandleFeaturesGet(c *handler.Context) (*wire.FeaturesGe
1111
res := wire.Features(features)
1212
return &res, nil
1313
}
14-
15-
func max(a, b int) int {
16-
if a > b {
17-
return a
18-
}
19-
return b
20-
}

kite-service/internal/core/plan/manager.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type PlanManagerConfig struct {
1717
type PlanManager struct {
1818
entitlementStore store.EntitlementStore
1919
subscriptionStore store.SubscriptionStore
20+
userStore store.UserStore
2021
plans []model.Plan
2122

2223
config PlanManagerConfig
@@ -25,12 +26,14 @@ type PlanManager struct {
2526
func NewPlanManager(
2627
entitlementStore store.EntitlementStore,
2728
subscriptionStore store.SubscriptionStore,
29+
userStore store.UserStore,
2830
plans []model.Plan,
2931
config PlanManagerConfig,
3032
) *PlanManager {
3133
return &PlanManager{
3234
entitlementStore: entitlementStore,
3335
subscriptionStore: subscriptionStore,
36+
userStore: userStore,
3437
plans: plans,
3538
config: config,
3639
}

kite-service/internal/core/plan/role.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (m *PlanManager) handOutRoles(ctx context.Context) error {
3434
return nil
3535
}
3636

37-
client := api.NewClient(m.config.DiscordBotToken)
37+
client := api.NewClient("Bot " + m.config.DiscordBotToken)
3838

3939
subscriptions, err := m.subscriptionStore.AllSubscriptions(ctx)
4040
if err != nil {
@@ -66,7 +66,17 @@ func (m *PlanManager) handOutRoles(ctx context.Context) error {
6666
continue
6767
}
6868

69-
discordUserID, err := strconv.ParseUint(sub.UserID, 10, 64)
69+
user, err := m.userStore.User(ctx, sub.UserID)
70+
if err != nil {
71+
slog.Error(
72+
"Failed to get user by ID",
73+
slog.String("error", err.Error()),
74+
slog.String("subscription_id", sub.ID),
75+
)
76+
continue
77+
}
78+
79+
discordUserID, err := strconv.ParseUint(user.DiscordID, 10, 64)
7080
if err != nil {
7181
slog.Error(
7282
"Failed to parse discord user ID from subscription",

kite-service/internal/db/postgres/pgmodel/entitlements.sql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kite-service/internal/db/postgres/queries/entitlements.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
SELECT * FROM entitlements WHERE app_id = $1 ORDER BY created_at DESC;
33

44
-- name: GetActiveEntitlements :many
5-
SELECT * FROM entitlements WHERE app_id = $1 AND ends_at IS NULL OR ends_at > $2 ORDER BY created_at DESC;
5+
SELECT * FROM entitlements WHERE app_id = $1 AND (ends_at IS NULL OR ends_at > $2) ORDER BY created_at DESC;
66

77
-- name: UpsertSubscriptionEntitlement :one
88
INSERT INTO entitlements (

kite-web/src/components/app/AppPricingList.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export default function AppPricingList() {
8989
<CheckIcon className="text-green-500" />{" "}
9090
<h3 className="ml-2">
9191
{pricing.feature_max_collaborators} Collaborator
92+
{pricing.feature_max_collaborators === 1 ? "" : "s"}
9293
</h3>
9394
</span>
9495
<span className="flex">

kite-web/src/components/app/AppSettingsCollaborators.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { MinusIcon } from "lucide-react";
2020
import ConfirmDialog from "../common/ConfirmDialog";
2121
import { Button } from "../ui/button";
2222
import AppCollaboratorAddDialog from "./AppCollaboratorAddDialog";
23+
import { toast } from "sonner";
2324

2425
export default function AppSettingsCollaborators() {
2526
const appId = useAppId();
@@ -67,7 +68,15 @@ export default function AppSettingsCollaborators() {
6768
title="Remove Collaborator"
6869
description="Are you sure you want to remove this collaborator?"
6970
onConfirm={() => {
70-
deleteMutation.mutate(collaborator!.user.id);
71+
deleteMutation.mutate(collaborator!.user.id, {
72+
onSuccess: (res) => {
73+
if (!res.success) {
74+
toast.error(
75+
`Failed to remove collaborator: ${res.error.message} (${res.error.code})`
76+
);
77+
}
78+
},
79+
});
7180
}}
7281
>
7382
<Button variant="ghost" size="icon">

kite-web/src/components/app/AppSubscriptionListEntry.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,16 @@ export default function AppSubscriptionListEntry({
4848
</div>
4949
</div>
5050
</CardHeader>
51-
<CardFooter className="gap-3">
52-
{subscription.manageable && (
53-
<>
54-
<Button variant="outline" onClick={() => updatePaymentMethod()}>
55-
Update Billing
56-
</Button>
57-
<Button variant="outline" onClick={() => openCustomerPortal()}>
58-
Manage
59-
</Button>
60-
</>
61-
)}
62-
</CardFooter>
51+
{subscription.manageable && (
52+
<CardFooter className="gap-3">
53+
<Button variant="outline" onClick={() => updatePaymentMethod()}>
54+
Update Billing
55+
</Button>
56+
<Button variant="outline" onClick={() => openCustomerPortal()}>
57+
Manage
58+
</Button>
59+
</CardFooter>
60+
)}
6361
</Card>
6462
);
6563
}

0 commit comments

Comments
 (0)