Modular logistics and supply chain operating system (LSOS)
JavaScript driver-appfleet-managementfreight-managementinfrastructureinventory-managementlast-mile-deliverylogisticsondemandopen-sourceorder-managementroute-optimizationsupply-chain-managementtracking-and-monitoringtransport-management-systemtransportationwarehouse-management
created frontend for saving
TemuulenBM9c1655167dd3
diff --git a/console/app/components/two-fa-settings.js b/console/app/components/two-fa-settings.jsindex 2a9f7bde..241b0de0 100644--- a/console/app/components/two-fa-settings.js+++ b/console/app/components/two-fa-settings.js@@ -31,9 +31,12 @@ export default class TwoFaSettingsComponent extends Component {} else {this.selected2FAMethod = this.TwoFaMethods.find((method) => method.recommended);}++ console.log('selected2FAMethod:', this.selected2FAMethod);}@action select2FAMethod(method) {this.selected2FAMethod = method;+ console.log('selected2FAMethod:', this.selected2FAMethod);}}diff --git a/console/app/controllers/console/admin/two-fa-settings.js b/console/app/controllers/console/admin/two-fa-settings.jsindex a3d1bdb6..058797eb 100644--- a/console/app/controllers/console/admin/two-fa-settings.js+++ b/console/app/controllers/console/admin/two-fa-settings.js@@ -4,56 +4,72 @@ import { action } from '@ember/object';import { tracked } from '@glimmer/tracking';export default class ConsoleAdminTwoFaSettingsController extends Controller {+ /**+ * Inject the notifications service.+ *+ * @memberof ConsoleAdminTwoFaSettingsController+ */@service notifications;- @service currentUser;++ /**+ * Inject the fetch service.+ *+ * @memberof ConsoleAdminTwoFaSettingsController+ */+ @service fetch;@tracked selected2FAMethod;- @tracked is2FAEnabled = false;-- // @action- // async saveSettings() {- // const currentUser = this.currentUser.user;- // if (currentUser) {- // console.log('Before setting meta:', currentUser.meta);- // currentUser.meta = {- // two_factor_method: this.selected2FAMethod,- // };- // console.log('After setting meta:', currentUser.meta);- // try {- // await currentUser.save();- // this.notifications.success('Settings saved successfully.');- // } catch (error) {- // console.error('Error saving settings:', error);- // this.notifications.error('Failed to save settings.');- // }- // } else {- // console.error('Current user not found.');- // this.notifications.error('User not found.');- // }- // }-- @action- async saveSettings() {- const currentUser = this.currentUser.user;- if (currentUser) {- if (this.selected2FAMethod) {- currentUser.meta = {- two_factor_method: this.selected2FAMethod,- };- try {- await currentUser.save();- this.notifications.success('Settings saved successfully.');- } catch (error) {- console.error('Error saving settings:', error);- this.notifications.error('Failed to save settings.');- }- } else {- console.error('No selected 2FA method.');- this.notifications.warning('Please select a 2FA method before saving.');- }- } else {- console.error('Current user not found.');- this.notifications.error('User not found.');- }++ @tracked is2FAEnabled;++ /**+ * The 2FA settings value JSON.+ *+ * @memberof ConsoleAdminNotificationsController+ * @var {Object}+ */+ @tracked twoFaSettings = {+ selectedMethod: null,+ isEnabled: false,+ };++ /**+ * Tracked property for the loading state+ *+ * @memberof ConsoleAdminTwoFaSettingsController+ * @var {Boolean}+ */+ @tracked isLoading = false;++ constructor(){+ super(...arguments);+ }++ /**+ * Save Two Factor settings to the server.+ *+ * @action+ * @method saveSettings+ * @returns {Promise}+ * @memberof ConsoleAdminTwoFaSettingsController+ */+ @action saveSettings() {+ const { twoFaSettings } = this;++ console.log('settings', twoFaSettings)++ this.isLoading = true;++ return this.fetch+ .post('two-fa-settings/save-settings', { twoFaSettings })+ .then(() => {+ this.notifications.success('2FA settings successfully saved.');+ })+ .catch((error) => {+ this.notifications.serverError(error);+ })+ .finally(() => {+ this.isLoading = false;+ });}}diff --git a/console/app/models/user.js b/console/app/models/user.jsindex 2c687d1c..28abb81c 100644--- a/console/app/models/user.js+++ b/console/app/models/user.js@@ -80,7 +80,7 @@ export default class UserModel extends Model {@not('isPhoneVerified') phoneIsNotVerified;/** @computed */- @computed('meta') get isTwoFactorEnabled() {+ @computed('meta.two_factor_enabled') get isTwoFactorEnabled() {return this.meta && this.meta.two_factor_enabled;}diff --git a/console/app/router.js b/console/app/router.jsindex 83018ed9..913e0dae 100644--- a/console/app/router.js+++ b/console/app/router.js@@ -11,7 +11,6 @@ Router.map(function () {this.route('login', { path: '/' });this.route('forgot-password');this.route('reset-password');- this.route('two-fa');});this.route('onboard', function () {this.route('verify-email');@@ -58,15 +57,15 @@ Router.map(function () {path: 'iam',});- this.mount('@fleetbase/storefront-engine', {- as: 'storefront',- path: 'storefront',- });-this.mount('@fleetbase/fleetops-engine', {as: 'fleet-ops',path: 'fleet-ops',});++ this.mount('@fleetbase/storefront-engine', {+ as: 'storefront',+ path: 'storefront',+ });});this.route('install');});diff --git a/console/app/routes/console/admin/two-fa-settings.js b/console/app/routes/console/admin/two-fa-settings.jsindex cd82a0a2..234cddf0 100644--- a/console/app/routes/console/admin/two-fa-settings.js+++ b/console/app/routes/console/admin/two-fa-settings.js@@ -1,10 +1,3 @@import Route from '@ember/routing/route';-import { inject as service } from '@ember/service';-export default class ConsoleAdminTwoFaSettingsRoute extends Route {- @service store;-- model(params) {- return this.store.query('user', params);- }-}+export default class ConsoleAdminTwoFaSettingsRoute extends Route {}diff --git a/console/app/serializers/two-fa-settings.js b/console/app/serializers/two-fa-settings.jsnew file mode 100644index 00000000..afbe35f5--- /dev/null+++ b/console/app/serializers/two-fa-settings.js@@ -0,0 +1,4 @@+import ApplicationSerializer from '@fleetbase/ember-core/serializers/application';+import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';++export default class TwoFaSettingsSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {}diff --git a/console/app/templates/console/admin/two-fa-settings.hbs b/console/app/templates/console/admin/two-fa-settings.hbsindex 1815fa45..73358689 100644--- a/console/app/templates/console/admin/two-fa-settings.hbs+++ b/console/app/templates/console/admin/two-fa-settings.hbs@@ -7,8 +7,8 @@<div class="container mx-auto h-screen" {{increase-height-by 1200}}><div class="max-w-3xl my-10 mx-auto space-y-4"><ContentPanel @title="Two-Factor Authentication Settings" @open={{true}} @pad={{true}} @panelBodyClass="bg-white dark:bg-gray-800">- <TwoFaSettings />+ <TwoFaSettings @twoFaSettings={{this.twoFaSettings}} @selected2FAMethod={{this.selected2FAMethod}} @is2FAEnabled={{this.is2FAEnabled}} @toggle2FA={{this.toggle2FA}}/></ContentPanel></div></div>-</Layout::Section::Body>+</Layout::Section::Body>\ No newline at end of filediff --git a/console/router.map.js b/console/router.map.jsindex c659921d..559b6b25 100644--- a/console/router.map.js+++ b/console/router.map.js@@ -43,6 +43,7 @@ Router.map(function () {});this.route('branding');this.route('notifications');+ this.route('two-fa-settings');this.route('virtual', { path: '/:slug/:view' });});});diff --git a/console/tests/unit/serializers/two-fa-settings-test.js b/console/tests/unit/serializers/two-fa-settings-test.jsnew file mode 100644index 00000000..1e572a22--- /dev/null+++ b/console/tests/unit/serializers/two-fa-settings-test.js@@ -0,0 +1,23 @@+import { module, test } from 'qunit';+import { setupTest } from '@fleetbase/console/tests/helpers';++module('Unit | Serializer | two fa settings', function (hooks) {+ setupTest(hooks);++ // Replace this with your real tests.+ test('it exists', function (assert) {+ let store = this.owner.lookup('service:store');+ let serializer = store.serializerFor('two-fa-settings');++ assert.ok(serializer);+ });++ test('it serializes records', function (assert) {+ let store = this.owner.lookup('service:store');+ let record = store.createRecord('two-fa-settings', {});++ let serializedRecord = record.serialize();++ assert.ok(serializedRecord);+ });+});