Skip to content

Commit 3e6ba69

Browse files
authored
Merge pull request #29 from fleetbase/dev-v0.1.6
v0.1.6
2 parents c54b945 + c770c2c commit 3e6ba69

27 files changed

+1207
-93
lines changed

addon/controllers/application.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
import Controller from '@ember/controller';
2+
import config from '../config/environment';
23

3-
export default class ApplicationController extends Controller {}
4+
export default class ApplicationController extends Controller {
5+
get selfHostedRegistry() {
6+
return config.registry.selfHosted === true;
7+
}
8+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import Controller from '@ember/controller';
2+
import { inject as service } from '@ember/service';
3+
import { tracked } from '@glimmer/tracking';
4+
import { action } from '@ember/object';
5+
import { loadConnectAndInitialize } from '@stripe/connect-js';
6+
import config from '../../../config/environment';
7+
8+
export default class DevelopersPaymentsSettingsController extends Controller {
9+
@service fetch;
10+
@service notifications;
11+
12+
@tracked connectInstance;
13+
@tracked accountManagementComponent;
14+
@tracked isLoading = true;
15+
16+
@action
17+
async setupStripe(element) {
18+
try {
19+
await this.initializeStripe();
20+
if (this.accountManagementComponent) {
21+
element.appendChild(this.accountManagementComponent);
22+
}
23+
this.isLoading = false;
24+
} catch (error) {
25+
this.notifications.serverError(error);
26+
this.isLoading = false;
27+
}
28+
}
29+
30+
async fetchClientSecret() {
31+
try {
32+
const { clientSecret } = await this.fetch.post('payments/account-management-session', {}, { namespace: '~registry/v1' });
33+
return clientSecret;
34+
} catch (error) {
35+
this.notifications.serverError(error);
36+
return null;
37+
}
38+
}
39+
40+
async initializeStripe() {
41+
if (this.connectInstance) {
42+
return;
43+
}
44+
45+
this.connectInstance = loadConnectAndInitialize({
46+
publishableKey: config.stripe.publishableKey,
47+
fetchClientSecret: this.fetchClientSecret.bind(this),
48+
appearance: {
49+
overlays: 'dialog',
50+
variables: {
51+
colorPrimary: '#635BFF',
52+
},
53+
},
54+
});
55+
56+
this.accountManagementComponent = this.connectInstance.create('account-management');
57+
}
58+
}

addon/routes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default buildRoutes(function () {
1818
this.route('payments', function () {
1919
this.route('index', { path: '/' });
2020
this.route('onboard');
21+
this.route('settings');
2122
});
2223
this.route('credentials');
2324
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import Route from '@ember/routing/route';
2+
import { inject as service } from '@ember/service';
3+
4+
export default class DevelopersPaymentsSettingsRoute extends Route {
5+
@service notifications;
6+
@service hostRouter;
7+
@service fetch;
8+
@service intl;
9+
10+
async beforeModel() {
11+
// Check if user has a Stripe Connect account before allowing access
12+
try {
13+
const { hasStripeConnectAccount } = await this.fetch.get('payments/has-stripe-connect-account', {}, { namespace: '~registry/v1' });
14+
if (!hasStripeConnectAccount) {
15+
this.notifications.warning(this.intl.t('registry-bridge.developers.payments.no-account-warning'));
16+
return this.hostRouter.transitionTo('console.extensions.payments.onboard');
17+
}
18+
} catch (error) {
19+
this.notifications.serverError(error);
20+
return this.hostRouter.transitionTo('console.extensions.payments');
21+
}
22+
}
23+
}

addon/templates/application.hbs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,34 @@
2323
</LinkTo>
2424
{{/each}}
2525
</Layout::Sidebar::Panel>
26-
<Layout::Sidebar::Panel @open={{true}} @title="Developers">
27-
<Layout::Sidebar::Item
28-
@route="console.extensions.developers.extensions"
29-
@icon="box-archive"
30-
@permission="registry-bridge list extension-bundle"
31-
@visible={{can "registry-bridge see extension-bundle"}}
32-
>Extensions</Layout::Sidebar::Item>
33-
<Layout::Sidebar::Item
34-
@route="console.extensions.developers.analytics"
35-
@icon="chart-simple"
36-
@permission="registry-bridge list extension-analytic"
37-
@visible={{can "registry-bridge see extension-analytic"}}
38-
>Analytics</Layout::Sidebar::Item>
39-
<Layout::Sidebar::Item
40-
@route="console.extensions.developers.payments"
41-
@icon="cash-register"
42-
@permission="registry-bridge list extension-payment"
43-
@visible={{can "registry-bridge see extension-payment"}}
44-
>Payments</Layout::Sidebar::Item>
45-
<Layout::Sidebar::Item
46-
@route="console.extensions.developers.credentials"
47-
@icon="key"
48-
@permission="registry-bridge list registry-token"
49-
@visible={{can "registry-bridge see registry-token"}}
50-
>Credentials</Layout::Sidebar::Item>
51-
</Layout::Sidebar::Panel>
26+
{{#if this.selfHostedRegistry}}
27+
<Layout::Sidebar::Panel @open={{true}} @title="Developers">
28+
<Layout::Sidebar::Item
29+
@route="console.extensions.developers.extensions"
30+
@icon="box-archive"
31+
@permission="registry-bridge list extension-bundle"
32+
@visible={{can "registry-bridge see extension-bundle"}}
33+
>Extensions</Layout::Sidebar::Item>
34+
<Layout::Sidebar::Item
35+
@route="console.extensions.developers.analytics"
36+
@icon="chart-simple"
37+
@permission="registry-bridge list extension-analytic"
38+
@visible={{can "registry-bridge see extension-analytic"}}
39+
>Analytics</Layout::Sidebar::Item>
40+
<Layout::Sidebar::Item
41+
@route="console.extensions.developers.payments"
42+
@icon="cash-register"
43+
@permission="registry-bridge list extension-payment"
44+
@visible={{can "registry-bridge see extension-payment"}}
45+
>Payments</Layout::Sidebar::Item>
46+
<Layout::Sidebar::Item
47+
@route="console.extensions.developers.credentials"
48+
@icon="key"
49+
@permission="registry-bridge list registry-token"
50+
@visible={{can "registry-bridge see registry-token"}}
51+
>Credentials</Layout::Sidebar::Item>
52+
</Layout::Sidebar::Panel>
53+
{{/if}}
5254
<Spacer @height="200px" />
5355
</EmberWormhole>
5456

addon/templates/developers/payments/index.hbs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
<Layout::Section::Header @title="Payments">
22
{{#if this.hasStripeConnectAccount}}
3-
<div class="flex flex-row space-x-1">
4-
<span class="text-sm text-black dark:text-white font-bold">Total Amount:</span>
5-
<span class="text-sm text-black dark:text-white">{{format-currency @model.total_amount "USD"}}</span>
3+
<div class="flex items-center space-x-4">
4+
<LinkTo @route="developers.payments.settings" class="btn btn-primary">
5+
<FaIcon @icon="cog" class="mr-1" />
6+
{{t "registry-bridge.developers.payments.manage-account"}}
7+
</LinkTo>
8+
<div class="flex flex-row space-x-1">
9+
<span class="text-sm text-black dark:text-white font-bold">Total Amount:</span>
10+
<span class="text-sm text-black dark:text-white">{{format-currency @model.total_amount "USD"}}</span>
11+
</div>
612
</div>
713
{{/if}}
814
</Layout::Section::Header>

addon/templates/developers/payments/onboard.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
</div>
3939
<div
4040
id="embedded-onboarding-container"
41-
class="min-h-20 bg-gray-50 dark:bg-gray-100 shadow-md rounded-lg border border-gray-300 dark:border-gray-900 {{unless this.onboardInProgress 'hidden'}}"
41+
class="p-4 min-h-20 bg-gray-50 dark:bg-gray-100 shadow-md rounded-lg border border-gray-300 dark:border-gray-900 {{unless this.onboardInProgress 'hidden'}}"
4242
{{did-insert (fn this.createTrackedElement "embeddedOnboardingContainer")}}
4343
>
4444
</div>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Layout::Section::Header @title={{t "registry-bridge.developers.payments.settings.title"}} />
2+
3+
<Layout::Section::Body class="overflow-y-scroll h-full">
4+
<div class="container">
5+
<div class="max-w-5xl mx-auto mt-4">
6+
<div class="content">
7+
<div class="mb-4">
8+
<p class="text-sm text-gray-700 dark:text-gray-300">
9+
{{t "registry-bridge.developers.payments.settings.description"}}
10+
</p>
11+
</div>
12+
{{#if this.isLoading}}
13+
<div class="flex items-center justify-center p-8">
14+
<Spinner
15+
@loadingMessage={{t "registry-bridge.developers.payments.settings.loading"}}
16+
@loadingMessageClass="ml-2 text-black dark:text-white"
17+
@wrapperClass="flex flex-row items-center"
18+
/>
19+
</div>
20+
{{/if}}
21+
<div
22+
id="account-management-container"
23+
{{did-insert this.setupStripe}}
24+
class="p-4 min-h-20 bg-gray-50 dark:bg-gray-100 shadow-md rounded-lg border border-gray-300 dark:border-gray-900"
25+
>
26+
</div>
27+
</div>
28+
</div>
29+
</div>
30+
</Layout::Section::Body>

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fleetbase/registry-bridge",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"description": "Internal Bridge between Fleetbase API and Extensions Registry",
55
"keywords": [
66
"fleetbase-extension",

config/environment.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ module.exports = function (environment) {
1313
stripe: {
1414
publishableKey: getenv('STRIPE_KEY'),
1515
},
16+
registry: {
17+
selfHosted: toBoolean(getenv('SELF_HOSTED_REGISTRY', false)),
18+
},
1619
};
1720

1821
return ENV;
@@ -26,3 +29,23 @@ function getMountedEngineRoutePrefix() {
2629

2730
return `console.${mountedEngineRoutePrefix}.`;
2831
}
32+
33+
function toBoolean(value) {
34+
switch (value) {
35+
case 'true':
36+
case '1':
37+
case 1:
38+
case true:
39+
return true;
40+
case 'false':
41+
case '0':
42+
case 0:
43+
case false:
44+
case null:
45+
case undefined:
46+
case '':
47+
return false;
48+
default:
49+
return false;
50+
}
51+
}

0 commit comments

Comments
 (0)