From aaacf9d4d2ab624ba5eb04c94f23191e7cd459c8 Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Fri, 16 Dec 2022 11:59:27 -0800 Subject: [PATCH] feat: Allow users to disable marking offline automatically (#6079) Co-authored-by: Nithin David <1277421+nithindavid@users.noreply.github.com> --- app/controllers/api/v1/profiles_controller.rb | 8 ++ app/javascript/dashboard/api/auth.js | 6 ++ app/javascript/dashboard/api/endPoints.js | 3 + .../components/layout/AvailabilityStatus.vue | 79 ++++++++++++++++--- .../layout/sidebarComponents/OptionsMenu.vue | 4 +- .../dashboard/components/ui/Switch.vue | 17 +++- .../dashboard/i18n/locale/en/settings.json | 8 +- .../dashboard/store/modules/auth.js | 17 ++++ .../store/modules/specs/auth/actions.spec.js | 32 ++++++++ .../components/ui/dropdown/DropdownHeader.vue | 1 + .../api/v1/profiles/auto_offline.jbuilder | 1 + config/integration/apps.yml | 1 - config/routes.rb | 1 + .../api/v1/profiles_controller_spec.rb | 24 ++++++ 14 files changed, 188 insertions(+), 14 deletions(-) create mode 100644 app/views/api/v1/profiles/auto_offline.jbuilder diff --git a/app/controllers/api/v1/profiles_controller.rb b/app/controllers/api/v1/profiles_controller.rb index 20b8e7ae8..cbf801e82 100644 --- a/app/controllers/api/v1/profiles_controller.rb +++ b/app/controllers/api/v1/profiles_controller.rb @@ -18,6 +18,10 @@ class Api::V1::ProfilesController < Api::BaseController head :ok end + def auto_offline + @user.account_users.find_by!(account_id: auto_offline_params[:account_id]).update!(auto_offline: auto_offline_params[:auto_offline] || false) + end + def availability @user.account_users.find_by!(account_id: availability_params[:account_id]).update!(availability: availability_params[:availability]) end @@ -37,6 +41,10 @@ class Api::V1::ProfilesController < Api::BaseController params.require(:profile).permit(:account_id, :availability) end + def auto_offline_params + params.require(:profile).permit(:account_id, :auto_offline) + end + def profile_params params.require(:profile).permit( :email, diff --git a/app/javascript/dashboard/api/auth.js b/app/javascript/dashboard/api/auth.js index ef1762f46..19ba40a42 100644 --- a/app/javascript/dashboard/api/auth.js +++ b/app/javascript/dashboard/api/auth.js @@ -144,6 +144,12 @@ export default { }); }, + updateAutoOffline(accountId, autoOffline = false) { + return axios.post(endPoints('autoOffline').url, { + profile: { account_id: accountId, auto_offline: autoOffline }, + }); + }, + deleteAvatar() { return axios.delete(endPoints('deleteAvatar').url); }, diff --git a/app/javascript/dashboard/api/endPoints.js b/app/javascript/dashboard/api/endPoints.js index 8deb8d56a..678386d50 100644 --- a/app/javascript/dashboard/api/endPoints.js +++ b/app/javascript/dashboard/api/endPoints.js @@ -16,6 +16,9 @@ const endPoints = { availabilityUpdate: { url: '/api/v1/profile/availability', }, + autoOffline: { + url: '/api/v1/profile/auto_offline', + }, logout: { url: 'auth/sign_out', }, diff --git a/app/javascript/dashboard/components/layout/AvailabilityStatus.vue b/app/javascript/dashboard/components/layout/AvailabilityStatus.vue index 1c70e6755..0a2698a9a 100644 --- a/app/javascript/dashboard/components/layout/AvailabilityStatus.vue +++ b/app/javascript/dashboard/components/layout/AvailabilityStatus.vue @@ -18,12 +18,35 @@ + +
+ + + + {{ $t('SIDEBAR.SET_AUTO_OFFLINE.TEXT') }} + +
+ + +
+