-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: plan ui * feat: billing ui * feat: settings plan comparison dialog * feat: complete plan+billing ui * feat: backend integration * chore: cleaning * chore: fixes after merge
- Loading branch information
Showing
23 changed files
with
1,805 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
frontend/appflowy_flutter/lib/workspace/application/settings/plan/settings_plan_bloc.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import 'package:flutter/foundation.dart'; | ||
|
||
import 'package:appflowy/core/helpers/url_launcher.dart'; | ||
import 'package:appflowy/user/application/user_service.dart'; | ||
import 'package:appflowy/workspace/application/workspace/workspace_service.dart'; | ||
import 'package:appflowy_backend/log.dart'; | ||
import 'package:appflowy_backend/protobuf/flowy-error/code.pbenum.dart'; | ||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart'; | ||
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'; | ||
import 'package:appflowy_backend/protobuf/flowy-user/workspace.pb.dart'; | ||
import 'package:appflowy_backend/protobuf/flowy-user/workspace.pbserver.dart'; | ||
import 'package:bloc/bloc.dart'; | ||
import 'package:collection/collection.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
part 'settings_plan_bloc.freezed.dart'; | ||
|
||
class SettingsPlanBloc extends Bloc<SettingsPlanEvent, SettingsPlanState> { | ||
SettingsPlanBloc({ | ||
required this.workspaceId, | ||
}) : super(const _Initial()) { | ||
_service = WorkspaceService(workspaceId: workspaceId); | ||
|
||
on<SettingsPlanEvent>((event, emit) async { | ||
await event.when( | ||
started: () async { | ||
emit(const SettingsPlanState.loading()); | ||
|
||
final snapshots = await Future.wait([ | ||
_service.getWorkspaceUsage(), | ||
UserBackendService.getWorkspaceSubscriptions(), | ||
_service.getBillingPortal(), | ||
]); | ||
|
||
FlowyError? error; | ||
|
||
final usageResult = snapshots.first.fold( | ||
(s) => s as WorkspaceUsagePB, | ||
(f) { | ||
error = f; | ||
return null; | ||
}, | ||
); | ||
|
||
final subscription = snapshots[1].fold( | ||
(s) => | ||
(s as RepeatedWorkspaceSubscriptionPB) | ||
.items | ||
.firstWhereOrNull((i) => i.workspaceId == workspaceId) ?? | ||
WorkspaceSubscriptionPB( | ||
workspaceId: workspaceId, | ||
subscriptionPlan: SubscriptionPlanPB.None, | ||
isActive: true, | ||
), | ||
(f) { | ||
error = f; | ||
return null; | ||
}, | ||
); | ||
|
||
final billingPortalResult = snapshots.last; | ||
final billingPortal = billingPortalResult.fold( | ||
(s) => s as BillingPortalPB, | ||
(e) { | ||
// Not a customer yet | ||
if (e.code == ErrorCode.InvalidParams) { | ||
return BillingPortalPB(); | ||
} | ||
|
||
error = e; | ||
return null; | ||
}, | ||
); | ||
|
||
if (usageResult == null || | ||
subscription == null || | ||
billingPortal == null || | ||
error != null) { | ||
return emit(SettingsPlanState.error(error: error)); | ||
} | ||
|
||
emit( | ||
SettingsPlanState.ready( | ||
workspaceUsage: usageResult, | ||
subscription: subscription, | ||
billingPortal: billingPortal, | ||
), | ||
); | ||
}, | ||
addSubscription: (plan) async { | ||
final result = await UserBackendService.createSubscription( | ||
workspaceId, | ||
SubscriptionPlanPB.Pro, | ||
); | ||
|
||
result.fold( | ||
(pl) => afLaunchUrlString(pl.paymentLink), | ||
(f) => Log.error(f.msg, f), | ||
); | ||
}, | ||
cancelSubscription: () async { | ||
await UserBackendService.cancelSubscription(workspaceId); | ||
}, | ||
); | ||
}); | ||
} | ||
|
||
late final String workspaceId; | ||
late final WorkspaceService _service; | ||
} | ||
|
||
@freezed | ||
class SettingsPlanEvent with _$SettingsPlanEvent { | ||
const factory SettingsPlanEvent.started() = _Started; | ||
const factory SettingsPlanEvent.addSubscription(SubscriptionPlanPB plan) = | ||
_AddSubscription; | ||
const factory SettingsPlanEvent.cancelSubscription() = _CancelSubscription; | ||
} | ||
|
||
@freezed | ||
class SettingsPlanState with _$SettingsPlanState { | ||
const factory SettingsPlanState.initial() = _Initial; | ||
|
||
const factory SettingsPlanState.loading() = _Loading; | ||
|
||
const factory SettingsPlanState.error({ | ||
@Default(null) FlowyError? error, | ||
}) = _Error; | ||
|
||
const factory SettingsPlanState.ready({ | ||
required WorkspaceUsagePB workspaceUsage, | ||
required WorkspaceSubscriptionPB subscription, | ||
required BillingPortalPB? billingPortal, | ||
}) = _Ready; | ||
} |
16 changes: 16 additions & 0 deletions
16
.../appflowy_flutter/lib/workspace/application/settings/plan/workspace_subscription_ext.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:appflowy/generated/locale_keys.g.dart'; | ||
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'; | ||
import 'package:appflowy_backend/protobuf/flowy-user/workspace.pb.dart'; | ||
import 'package:easy_localization/easy_localization.dart'; | ||
|
||
extension SubscriptionLabels on WorkspaceSubscriptionPB { | ||
String get label => switch (subscriptionPlan) { | ||
SubscriptionPlanPB.None => | ||
LocaleKeys.settings_planPage_planUsage_currentPlan_freeTitle.tr(), | ||
SubscriptionPlanPB.Pro => | ||
LocaleKeys.settings_planPage_planUsage_currentPlan_proTitle.tr(), | ||
SubscriptionPlanPB.Team => | ||
LocaleKeys.settings_planPage_planUsage_currentPlan_teamTitle.tr(), | ||
_ => 'N/A', | ||
}; | ||
} |
8 changes: 8 additions & 0 deletions
8
frontend/appflowy_flutter/lib/workspace/application/settings/plan/workspace_usage_ext.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'package:appflowy_backend/protobuf/flowy-user/workspace.pb.dart'; | ||
|
||
extension PresentableUsage on WorkspaceUsagePB { | ||
String get totalBlobInGb => | ||
(totalBlobBytesLimit.toInt() / 1024 / 1024 / 1024).round().toString(); | ||
String get currentBlobInGb => | ||
(totalBlobBytes.toInt() / 1024 / 1024 / 1024).round().toString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...end/appflowy_flutter/lib/workspace/presentation/settings/pages/settings_billing_view.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'package:appflowy/workspace/presentation/settings/shared/settings_body.dart'; | ||
import 'package:appflowy/workspace/presentation/settings/shared/settings_category.dart'; | ||
import 'package:appflowy/workspace/presentation/settings/shared/single_setting_action.dart'; | ||
import 'package:easy_localization/easy_localization.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../../../../generated/locale_keys.g.dart'; | ||
|
||
class SettingsBillingView extends StatelessWidget { | ||
const SettingsBillingView({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SettingsBody( | ||
title: LocaleKeys.settings_billingPage_title.tr(), | ||
description: LocaleKeys.settings_billingPage_description.tr(), | ||
children: [ | ||
SettingsCategory( | ||
title: LocaleKeys.settings_billingPage_plan_title.tr(), | ||
children: [ | ||
SingleSettingAction( | ||
label: LocaleKeys.settings_billingPage_plan_freeLabel.tr(), | ||
buttonLabel: | ||
LocaleKeys.settings_billingPage_plan_planButtonLabel.tr(), | ||
), | ||
SingleSettingAction( | ||
label: LocaleKeys.settings_billingPage_plan_billingPeriod.tr(), | ||
buttonLabel: | ||
LocaleKeys.settings_billingPage_plan_periodButtonLabel.tr(), | ||
), | ||
], | ||
), | ||
SettingsCategory( | ||
title: LocaleKeys.settings_billingPage_paymentDetails_title.tr(), | ||
children: [ | ||
SingleSettingAction( | ||
label: LocaleKeys.settings_billingPage_paymentDetails_methodLabel | ||
.tr(), | ||
buttonLabel: LocaleKeys | ||
.settings_billingPage_paymentDetails_methodButtonLabel | ||
.tr(), | ||
), | ||
], | ||
), | ||
], | ||
); | ||
} | ||
} |
Oops, something went wrong.