Skip to content

Commit

Permalink
Merge pull request #7115 from fjordllc/feature/display-elapsed-days-n…
Browse files Browse the repository at this point in the history
…umber-for-hibernated-user-on-users-list

ユーザー一覧ページにおいてメンターと管理者には休会中ユーザーの休会日と経過日数の表示されるようにした
  • Loading branch information
komagata authored Dec 31, 2023
2 parents 871da3d + 3f9e802 commit d9ff361
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 6 deletions.
12 changes: 9 additions & 3 deletions app/javascript/components/user.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
.col-xxl-3.col-xl-4.col-lg-4.col-md-6.col-xs-12
.users-item
.users-item__inner.a-card
.users-item__inactive-message.is-only-mentor(
v-if='currentUser.mentor && user.student_or_trainee && !user.active')
| 1ヶ月以上ログインがありません
.users-item__inactive-message-container.is-only-mentor(
v-if='(currentUser.mentor || currentUser.admin) && user.student_or_trainee')
.users-item__inactive-message(v-if='user.roles.includes("retired")')
| 退会しました
.users-item__inactive-message(
v-else-if='user.roles.includes("hibernationed")')
| 休会中: {{ user.hibernated_at }}〜({{ user.hibernation_elapsed_days }}日経過)
.users-item__inactive-message(v-else-if='!user.active')
| 1ヶ月以上ログインがありません
header.users-item__header
.users-item__header-inner
.users-item__header-start
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
height: 100%

.users-item__inactive-message
background-color: var(--background)
background-color: var(--disabled)
+text-block(.625rem 1.4, center)
padding: .25rem
+border-radius(top, .1875rem)
margin-bottom: -.25rem
margin: -1px -1px -.25rem

.users-item__inner
+media-breakpoint-up(md)
Expand All @@ -16,7 +16,7 @@

.users-item__header
+position(relative)
padding: 1rem
padding: .75rem 1rem
border-bottom: solid 1px var(--border-tint)

.users-item__header-inner
Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,10 @@ def last_hibernation
hibernations.order(:created_at).last
end

def hibernation_elapsed_days
(Time.zone.today - hibernated_at.to_date).to_i
end

def update_last_returned_at!
hibernation = last_hibernation
hibernation.returned_at = Date.current
Expand Down
5 changes: 5 additions & 0 deletions app/views/api/users/_list_user.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ json.company do
json.url company_url(user.company)
end
end

if user.hibernated?
json.hibernated_at l(user.hibernated_at, format: :year_and_date)
json.hibernation_elapsed_days user.hibernation_elapsed_days
end
10 changes: 10 additions & 0 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,16 @@ class UserTest < ActiveSupport::TestCase
assert target.sent_student_followup_message
end

test '#hibernation_elapsed_days' do
user = users(:kyuukai)

travel_to Time.zone.local(2020, 1, 10) do
elapsed_days = user.hibernation_elapsed_days

assert assert_equal 9, elapsed_days
end
end

test '#country_name' do
assert_equal '日本', users(:kimura).country_name
assert_equal '米国', users(:tom).country_name
Expand Down
14 changes: 14 additions & 0 deletions test/system/users_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -629,4 +629,18 @@ class UsersTest < ApplicationSystemTestCase
visit_with_auth user_path(user), 'komagata'
assert_no_text '休会中 / 休会から'
end

test 'show retirement message on users page' do
visit_with_auth users_path, 'komagata'
click_link('退会')
assert_selector '.users-item__inactive-message-container.is-only-mentor .users-item__inactive-message', text: '退会しました'
end

test 'show hibernation elasped days message on users page' do
travel_to Time.zone.local(2020, 1, 11, 0, 0, 0) do
visit_with_auth users_path, 'komagata'
click_link('休会')
assert_selector '.users-item__inactive-message-container.is-only-mentor .users-item__inactive-message', text: '休会中: 2020年01月01日〜(10日経過)'
end
end
end

0 comments on commit d9ff361

Please sign in to comment.