From 5b746d3c13929357d441c889213505ec7c71cf13 Mon Sep 17 00:00:00 2001 From: naokinaokiboo Date: Tue, 12 Mar 2024 12:21:07 +0900 Subject: [PATCH 01/11] =?UTF-8?q?=E6=8B=9B=E5=BE=85URL=E3=83=9A=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/invitation_url_controller.rb | 5 +++ app/models/user.rb | 6 ++++ app/views/admin/_admin_page_tabs.html.slim | 4 +++ .../admin/invitation_url/index.html.slim | 31 +++++++++++++++++++ config/routes/admin.rb | 1 + 5 files changed, 47 insertions(+) create mode 100644 app/controllers/admin/invitation_url_controller.rb create mode 100644 app/views/admin/invitation_url/index.html.slim diff --git a/app/controllers/admin/invitation_url_controller.rb b/app/controllers/admin/invitation_url_controller.rb new file mode 100644 index 00000000000..0a71316f10a --- /dev/null +++ b/app/controllers/admin/invitation_url_controller.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class Admin::InvitationUrlController < AdminController + def index; end +end diff --git a/app/models/user.rb b/app/models/user.rb index dac0036ef2f..bdcdf628d74 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -22,6 +22,12 @@ class User < ApplicationRecord DEFAULT_REGULAR_EVENT_ORGANIZER = 'komagata' HIBERNATION_LIMIT = 6.months + INVITATION_ROLES = [ + ['アドバイザー', :adviser], + ['研修生', :trainee], + ['メンター', :mentor] + ].freeze + enum job: { student: 0, office_worker: 2, diff --git a/app/views/admin/_admin_page_tabs.html.slim b/app/views/admin/_admin_page_tabs.html.slim index ac36b852a18..89d84d3b08a 100644 --- a/app/views/admin/_admin_page_tabs.html.slim +++ b/app/views/admin/_admin_page_tabs.html.slim @@ -21,3 +21,7 @@ = link_to 'お問い合わせ', admin_inquiries_path, class: "page-tabs__item-link #{current_link(/^admin-inquiries/)}" + li.page-tabs__item + = link_to '招待URL', + admin_invitation_url_index_path, + class: "page-tabs__item-link #{current_link(/^admin-invitation_url/)}" diff --git a/app/views/admin/invitation_url/index.html.slim b/app/views/admin/invitation_url/index.html.slim new file mode 100644 index 00000000000..3deb3bd2f44 --- /dev/null +++ b/app/views/admin/invitation_url/index.html.slim @@ -0,0 +1,31 @@ +- title '管理ページ' + +header.page-header + .container + .page-header__inner + h1.page-header__title = title + += render 'admin/admin_page_tabs' + +.page-main + header.page-main-header + .container + .page-main-header__inner + h1.page-main-header__title + | 招待URL + hr.a-border + .page-body + .container.is-lg + .invitation-elements + .invitation-element + = label_tag :company, '企業:', class: 'a-form-label' + = select_tag :company, options_from_collection_for_select(Company.order(created_at: :desc), :id, :name), class: 'js-invitation-company' + .invitation-element + = label_tag :role, 'ロール:', class: 'a-form-label' + = select_tag :role, options_for_select(User::INVITATION_ROLES), class: 'js-invitation-role' + .invitation-element + = label_tag :course, 'コース:', class: 'a-form-label' + = select_tag :course, options_from_collection_for_select(Course.order(:created_at), :id, :title), class: 'js-invitation-course' + span + | URL: + a.js-invitation-url diff --git a/config/routes/admin.rb b/config/routes/admin.rb index a8aaa99d881..84738149d17 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -10,5 +10,6 @@ end resources :campaigns, only: %i(new create index edit update) resources :inquiries, only: %i(index show) + resources :invitation_url, only: %i(index) end end From 831f51b4e03a19897c01fdebbd85f3d72a55d976 Mon Sep 17 00:00:00 2001 From: naokinaokiboo Date: Tue, 12 Mar 2024 12:30:28 +0900 Subject: [PATCH 02/11] =?UTF-8?q?=E3=83=89=E3=83=AD=E3=83=83=E3=83=97?= =?UTF-8?q?=E3=83=80=E3=82=A6=E3=83=B3=E3=81=AE=E9=81=B8=E6=8A=9E=E9=A0=85?= =?UTF-8?q?=E7=9B=AE=E3=82=92=E5=85=83=E3=81=AB=E6=8B=9B=E5=BE=85URL?= =?UTF-8?q?=E3=82=92=E4=BD=9C=E6=88=90=E3=81=99=E3=82=8B=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/admin/invitation_url_controller.rb | 13 ++++++ app/javascript/invitation-url-updater.js | 44 +++++++++++++++++++ app/javascript/packs/application.js | 1 + config/routes/api.rb | 1 + 4 files changed, 59 insertions(+) create mode 100644 app/controllers/api/admin/invitation_url_controller.rb create mode 100644 app/javascript/invitation-url-updater.js diff --git a/app/controllers/api/admin/invitation_url_controller.rb b/app/controllers/api/admin/invitation_url_controller.rb new file mode 100644 index 00000000000..6d99313e684 --- /dev/null +++ b/app/controllers/api/admin/invitation_url_controller.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class API::Admin::InvitationUrlController < API::Admin::BaseController + def index + url = new_user_url( + company_id: params[:company_id], + role: params[:role], + course_id: params[:course_id], + token: ENV['TOKEN'] || 'token' + ) + render json: { url: } + end +end diff --git a/app/javascript/invitation-url-updater.js b/app/javascript/invitation-url-updater.js new file mode 100644 index 00000000000..21558b8697b --- /dev/null +++ b/app/javascript/invitation-url-updater.js @@ -0,0 +1,44 @@ +document.addEventListener('DOMContentLoaded', async () => { + const invitationElements = Array.from( + document.querySelectorAll('.invitation-elements select') + ) + const invitationUrl = document.querySelector('.js-invitation-url') + + if (!invitationElements || !invitationUrl) { + return + } + + const updateInvitationURL = async () => { + const invitationCompany = document.querySelector('.js-invitation-company') + const invitationRole = document.querySelector('.js-invitation-role') + const invitationCourse = document.querySelector('.js-invitation-course') + + const params = new URLSearchParams() + params.append( + 'company_id', + invitationCompany.options[invitationCompany.selectedIndex].value + ) + params.append( + 'role', + invitationRole.options[invitationRole.selectedIndex].value + ) + params.append( + 'course_id', + invitationCourse.options[invitationCourse.selectedIndex].value + ) + + const response = await fetch( + `/api/admin/invitation_url?${params.toString()}` + ).catch((error) => console.warn(error)) + const json = await response.json().catch((error) => console.warn(error)) + + invitationUrl.href = json.url + invitationUrl.textContent = json.url + } + + invitationElements.forEach((invitationElement) => { + invitationElement.addEventListener('change', updateInvitationURL) + }) + + await updateInvitationURL() +}) diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index 9f15579527f..461978aaad2 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -56,6 +56,7 @@ import '../upload-image-to-article.js' import '../header-dropdown.js' import '../editor-selection-form.js' import '../user_mentor_memo.js' +import '../invitation-url-updater.js' import VueMounter from '../VueMounter.js' import Books from '../components/books.vue' diff --git a/config/routes/api.rb b/config/routes/api.rb index 6a579e547e6..e3da61d5b89 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -5,6 +5,7 @@ namespace 'admin' do resource :count, controller: 'count', only: %i(show) resources :companies, only: %i(index destroy) + resources :invitation_url, only: %i(index) end namespace 'mentor' do resources :practices, only: %i(index) From 5908a39b394239aa10e44bb49da35686ce8d1e06 Mon Sep 17 00:00:00 2001 From: naokinaokiboo Date: Tue, 12 Mar 2024 12:40:12 +0900 Subject: [PATCH 03/11] =?UTF-8?q?=E6=8B=9B=E5=BE=85URL=E3=83=9A=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E3=81=AB=E9=96=A2=E3=81=99=E3=82=8B=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/system/admin/home_test.rb | 3 +- test/system/admin/invitation_url_test.rb | 53 ++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 test/system/admin/invitation_url_test.rb diff --git a/test/system/admin/home_test.rb b/test/system/admin/home_test.rb index 9d444345b2e..c1700ef4aeb 100644 --- a/test/system/admin/home_test.rb +++ b/test/system/admin/home_test.rb @@ -7,12 +7,13 @@ class Admin::HomeTest < ApplicationSystemTestCase visit_with_auth '/admin', 'komagata' assert_equal '管理ページ | FBC', title - assert_selector 'a.page-tabs__item-link', count: 5 + assert_selector 'a.page-tabs__item-link', count: 6 assert_selector '.page-tabs__item-link', text: '管理ページ' assert_selector '.page-tabs__item-link', text: 'ユーザー' assert_selector '.page-tabs__item-link', text: '企業' assert_selector '.page-tabs__item-link', text: 'お試し延長' assert_selector '.page-tabs__item-link', text: 'お問い合わせ' + assert_selector '.page-tabs__item-link', text: '招待URL' assert_no_selector '.page-tabs__item-link', text: 'プラクティス' assert_no_selector '.page-tabs__item-link', text: 'カテゴリー' assert_no_selector '.page-tabs__item-link', text: 'コース' diff --git a/test/system/admin/invitation_url_test.rb b/test/system/admin/invitation_url_test.rb new file mode 100644 index 00000000000..889f4c0f817 --- /dev/null +++ b/test/system/admin/invitation_url_test.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require 'application_system_test_case' + +class Admin::InvitationUrlTest < ApplicationSystemTestCase + test 'non-admin cannot be visited invitation-url page' do + visit_with_auth '/admin/invitation_url', 'kimura' + assert_text '管理者としてログインしてください' + end + + test 'show invitation-url page' do + visit_with_auth '/admin/invitation_url', 'komagata' + assert_equal '管理ページ | FBC', title + company = Company.order(created_at: :desc).first + course = Course.order(:created_at).first + assert_text "http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}/users/new?company_id=#{company.id}&course_id=#{course.id}&role=adviser&token=token" + end + + test 'change selected dropdown item' do + visit_with_auth '/admin/invitation_url', 'komagata' + assert_equal '招待URL | FBC', title + + company = companies(:company3) + course = courses(:course3) + find('.js-invitation-company').click + select(company.name) + find('.js-invitation-role').click + select('メンター') + find('.js-invitation-course') + select(course.title) + assert_text "http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}/users/new?company_id=#{company.id}&course_id=#{course.id}&role=mentor&token=token" + + company = companies(:company2) + course = courses(:course2) + find('.js-invitation-company').click + select(company.name) + find('.js-invitation-role').click + select('研修生') + find('.js-invitation-course') + select(course.title) + assert_text "http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}/users/new?company_id=#{company.id}&course_id=#{course.id}&role=trainee&token=token" + + company = companies(:company1) + course = courses(:course1) + find('.js-invitation-company').click + select(company.name) + find('.js-invitation-role').click + select('アドバイザー') + find('.js-invitation-course') + select(course.title) + assert_text "http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}/users/new?company_id=#{company.id}&course_id=#{course.id}&role=adviser&token=token" + end +end From 962b074b510ff4e377eef8486f5ab2c3cb13098a Mon Sep 17 00:00:00 2001 From: naokinaokiboo Date: Mon, 18 Mar 2024 15:01:16 +0900 Subject: [PATCH 04/11] =?UTF-8?q?=E3=83=AD=E3=83=BC=E3=83=AB=E3=81=AE?= =?UTF-8?q?=E9=81=B8=E6=8A=9E=E9=A0=85=E7=9B=AE=E5=90=8D=E3=82=92=E3=83=AD?= =?UTF-8?q?=E3=82=B1=E3=83=BC=E3=83=AB=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=81=AB=E5=AE=9A=E7=BE=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 6 +++--- config/locales/ja.yml | 4 ++++ test/system/admin/invitation_url_test.rb | 6 +++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index bdcdf628d74..b576c1aeb60 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -23,9 +23,9 @@ class User < ApplicationRecord HIBERNATION_LIMIT = 6.months INVITATION_ROLES = [ - ['アドバイザー', :adviser], - ['研修生', :trainee], - ['メンター', :mentor] + [I18n.t('invitation_role.adviser'), :adviser], + [I18n.t('invitation_role.trainee'), :trainee], + [I18n.t('invitation_role.mentor'), :mentor] ].freeze enum job: { diff --git a/config/locales/ja.yml b/config/locales/ja.yml index cedd91ea258..22574173908 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -371,6 +371,10 @@ ja: unchecked_no_replied: 未返信 unchecked_all: 全て campaign: お試し延長 + invitation_role: + adviser: アドバイザー + trainee: 研修生 + mentor: メンター watch: all: すべて true: コメントあり diff --git a/test/system/admin/invitation_url_test.rb b/test/system/admin/invitation_url_test.rb index 889f4c0f817..49446ec85ff 100644 --- a/test/system/admin/invitation_url_test.rb +++ b/test/system/admin/invitation_url_test.rb @@ -25,7 +25,7 @@ class Admin::InvitationUrlTest < ApplicationSystemTestCase find('.js-invitation-company').click select(company.name) find('.js-invitation-role').click - select('メンター') + select(I18n.t('invitation_role.mentor')) find('.js-invitation-course') select(course.title) assert_text "http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}/users/new?company_id=#{company.id}&course_id=#{course.id}&role=mentor&token=token" @@ -35,7 +35,7 @@ class Admin::InvitationUrlTest < ApplicationSystemTestCase find('.js-invitation-company').click select(company.name) find('.js-invitation-role').click - select('研修生') + select(I18n.t('invitation_role.trainee')) find('.js-invitation-course') select(course.title) assert_text "http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}/users/new?company_id=#{company.id}&course_id=#{course.id}&role=trainee&token=token" @@ -45,7 +45,7 @@ class Admin::InvitationUrlTest < ApplicationSystemTestCase find('.js-invitation-company').click select(company.name) find('.js-invitation-role').click - select('アドバイザー') + select(I18n.t('invitation_role.adviser')) find('.js-invitation-course') select(course.title) assert_text "http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}/users/new?company_id=#{company.id}&course_id=#{course.id}&role=adviser&token=token" From 5d986b9ca920e342c87f638802258a7aa6ddbe70 Mon Sep 17 00:00:00 2001 From: naokinaokiboo Date: Wed, 20 Mar 2024 13:59:08 +0900 Subject: [PATCH 05/11] =?UTF-8?q?=E3=83=96=E3=83=A9=E3=82=A6=E3=82=B6?= =?UTF-8?q?=E3=81=AE=E3=83=90=E3=83=83=E3=82=AF=E3=83=9C=E3=82=BF=E3=83=B3?= =?UTF-8?q?=E3=81=A7=E6=88=BB=E3=81=A3=E3=81=9F=E3=81=A8=E3=81=8D=E3=81=AB?= =?UTF-8?q?=E3=80=81=E9=81=B8=E6=8A=9E=E9=A0=85=E7=9B=AE=E3=81=A8=E8=A1=A8?= =?UTF-8?q?=E7=A4=BAURL=E3=81=8C=E7=95=B0=E3=81=AA=E3=82=8B=E4=B8=8D?= =?UTF-8?q?=E5=85=B7=E5=90=88=E3=81=AB=E5=AF=BE=E5=87=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/invitation-url-updater.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/javascript/invitation-url-updater.js b/app/javascript/invitation-url-updater.js index 21558b8697b..96a74525943 100644 --- a/app/javascript/invitation-url-updater.js +++ b/app/javascript/invitation-url-updater.js @@ -40,5 +40,5 @@ document.addEventListener('DOMContentLoaded', async () => { invitationElement.addEventListener('change', updateInvitationURL) }) - await updateInvitationURL() + window.addEventListener('pageshow', updateInvitationURL) }) From 09844a9ec514cd5a91e1d97ad18d0092110e0a47 Mon Sep 17 00:00:00 2001 From: machida Date: Tue, 26 Mar 2024 04:24:40 +0900 Subject: [PATCH 06/11] =?UTF-8?q?=E6=8B=9B=E5=BE=85URL=E3=83=9A=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E3=81=AE=E3=83=87=E3=82=B6=E3=82=A4=E3=83=B3=E8=AA=BF?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/invitation-url-updater.js | 3 +- .../admin/invitation_url/index.html.slim | 34 ++++++++++++------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/app/javascript/invitation-url-updater.js b/app/javascript/invitation-url-updater.js index 96a74525943..c0b6fd03c95 100644 --- a/app/javascript/invitation-url-updater.js +++ b/app/javascript/invitation-url-updater.js @@ -3,6 +3,7 @@ document.addEventListener('DOMContentLoaded', async () => { document.querySelectorAll('.invitation-elements select') ) const invitationUrl = document.querySelector('.js-invitation-url') + const invitationUrlText = document.querySelector('.js-invitation-url-text') if (!invitationElements || !invitationUrl) { return @@ -33,7 +34,7 @@ document.addEventListener('DOMContentLoaded', async () => { const json = await response.json().catch((error) => console.warn(error)) invitationUrl.href = json.url - invitationUrl.textContent = json.url + invitationUrlText.value = json.url } invitationElements.forEach((invitationElement) => { diff --git a/app/views/admin/invitation_url/index.html.slim b/app/views/admin/invitation_url/index.html.slim index 3deb3bd2f44..099804caeff 100644 --- a/app/views/admin/invitation_url/index.html.slim +++ b/app/views/admin/invitation_url/index.html.slim @@ -16,16 +16,24 @@ header.page-header hr.a-border .page-body .container.is-lg - .invitation-elements - .invitation-element - = label_tag :company, '企業:', class: 'a-form-label' - = select_tag :company, options_from_collection_for_select(Company.order(created_at: :desc), :id, :name), class: 'js-invitation-company' - .invitation-element - = label_tag :role, 'ロール:', class: 'a-form-label' - = select_tag :role, options_for_select(User::INVITATION_ROLES), class: 'js-invitation-role' - .invitation-element - = label_tag :course, 'コース:', class: 'a-form-label' - = select_tag :course, options_from_collection_for_select(Course.order(:created_at), :id, :title), class: 'js-invitation-course' - span - | URL: - a.js-invitation-url + .invitation.flex.flex-col.gap-4 + .invitation__elements.flex.gap-4.flex-col(class='md:flex-row') + .invitation__element.flex-1 + = label_tag :company, '企業', class: 'a-form-label' + .a-button.is-md.is-secondary.is-select.is-block + = select_tag :company, options_from_collection_for_select(Company.order(created_at: :desc), :id, :name), class: 'js-invitation-company' + .invitation__element.flex-1 + = label_tag :role, 'ロール', class: 'a-form-label' + .a-button.is-md.is-secondary.is-select.is-block + = select_tag :role, options_for_select(User::INVITATION_ROLES), class: 'js-invitation-role' + .invitation__element.flex-1 + = label_tag :course, 'コース', class: 'a-form-label' + .a-button.is-md.is-secondary.is-select.is-block + = select_tag :course, options_from_collection_for_select(Course.order(:created_at), :id, :title), class: 'js-invitation-course' + .invitation__url + .a-form-label + | URL + .invitation__url-inner.flex.gap-1 + input.js-invitation-url-text.a-text-input(type="text") + a.js-invitation-url.a-button.is-md.is-secondary.is-icon(class='h-[2.375rem]') + i.fa-solid.fa-arrow-up-right-from-square From 1c5619a2740d41ff5bba56e77ed4da599e6e7402 Mon Sep 17 00:00:00 2001 From: naokinaokiboo Date: Thu, 28 Mar 2024 09:49:15 +0900 Subject: [PATCH 07/11] =?UTF-8?q?=E3=83=87=E3=82=B6=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E8=AA=BF=E6=95=B4=E3=81=AB=E4=BC=B4=E3=81=84=E3=80=81javascrip?= =?UTF-8?q?t=E3=81=A7=E5=8F=96=E5=BE=97=E3=81=99=E3=82=8Bclass=E5=90=8D?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/invitation-url-updater.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/javascript/invitation-url-updater.js b/app/javascript/invitation-url-updater.js index c0b6fd03c95..02f865c066c 100644 --- a/app/javascript/invitation-url-updater.js +++ b/app/javascript/invitation-url-updater.js @@ -1,6 +1,6 @@ document.addEventListener('DOMContentLoaded', async () => { const invitationElements = Array.from( - document.querySelectorAll('.invitation-elements select') + document.querySelectorAll('.invitation__element select') ) const invitationUrl = document.querySelector('.js-invitation-url') const invitationUrlText = document.querySelector('.js-invitation-url-text') From 4dd22b40ca36e833c02bc865ffea1bb057ccc28f Mon Sep 17 00:00:00 2001 From: naokinaokiboo Date: Thu, 28 Mar 2024 09:50:21 +0900 Subject: [PATCH 08/11] =?UTF-8?q?javascript=E3=81=A7=E3=81=AEreturn?= =?UTF-8?q?=E3=81=AE=E6=9D=A1=E4=BB=B6=E3=81=AE=E9=96=93=E9=81=95=E3=81=84?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/invitation-url-updater.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/javascript/invitation-url-updater.js b/app/javascript/invitation-url-updater.js index 02f865c066c..c1ea71b0f5c 100644 --- a/app/javascript/invitation-url-updater.js +++ b/app/javascript/invitation-url-updater.js @@ -5,7 +5,7 @@ document.addEventListener('DOMContentLoaded', async () => { const invitationUrl = document.querySelector('.js-invitation-url') const invitationUrlText = document.querySelector('.js-invitation-url-text') - if (!invitationElements || !invitationUrl) { + if (invitationElements.length === 0 || !invitationUrlText || !invitationUrl) { return } From 0f7c8577147abefcaa7b42954fffb6f30873c6d5 Mon Sep 17 00:00:00 2001 From: naokinaokiboo Date: Thu, 28 Mar 2024 12:03:10 +0900 Subject: [PATCH 09/11] =?UTF-8?q?1=E3=81=A4=E3=81=AE=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=81=AE=E7=B2=92=E5=BA=A6=E3=82=92=E5=B0=8F=E3=81=95?= =?UTF-8?q?=E3=81=8F=E3=81=97=E3=80=81=E8=A4=87=E6=95=B0=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=81=AB=E5=88=86=E5=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/system/admin/invitation_url_test.rb | 71 +++++++++++++++--------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/test/system/admin/invitation_url_test.rb b/test/system/admin/invitation_url_test.rb index 49446ec85ff..ad10c811dfb 100644 --- a/test/system/admin/invitation_url_test.rb +++ b/test/system/admin/invitation_url_test.rb @@ -3,51 +3,72 @@ require 'application_system_test_case' class Admin::InvitationUrlTest < ApplicationSystemTestCase + setup do + @new_user_url = "http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}/users/new" + end + test 'non-admin cannot be visited invitation-url page' do visit_with_auth '/admin/invitation_url', 'kimura' assert_text '管理者としてログインしてください' end - test 'show invitation-url page' do + test 'admin can be visited invitation-url page' do visit_with_auth '/admin/invitation_url', 'komagata' assert_equal '管理ページ | FBC', title + end + + test 'show invitation-url page' do + visit_with_auth '/admin/invitation_url', 'komagata' company = Company.order(created_at: :desc).first + role = User::INVITATION_ROLES.first[1] course = Course.order(:created_at).first - assert_text "http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}/users/new?company_id=#{company.id}&course_id=#{course.id}&role=adviser&token=token" + expected = "#{@new_user_url}?company_id=#{company.id}&course_id=#{course.id}&role=#{role}&token=token" + + Timeout.timeout(Capybara.default_max_wait_time, StandardError) do + loop until find('.js-invitation-url-text').value == expected && find('.js-invitation-url')[:href] == expected + end end - test 'change selected dropdown item' do + test 'change selected company' do visit_with_auth '/admin/invitation_url', 'komagata' - assert_equal '招待URL | FBC', title - company = companies(:company3) - course = courses(:course3) + role = User::INVITATION_ROLES.first[1] + course = Course.order(:created_at).first + expected = "#{@new_user_url}?company_id=#{company.id}&course_id=#{course.id}&role=#{role}&token=token" + find('.js-invitation-company').click select(company.name) + Timeout.timeout(Capybara.default_max_wait_time, StandardError) do + loop until find('.js-invitation-url-text').value == expected && find('.js-invitation-url')[:href] == expected + end + end + + test 'change selected role' do + visit_with_auth '/admin/invitation_url', 'komagata' + company = Company.order(created_at: :desc).first + role_text = User::INVITATION_ROLES.second[0] + role = User::INVITATION_ROLES.second[1] + course = Course.order(:created_at).first + expected = "#{@new_user_url}?company_id=#{company.id}&course_id=#{course.id}&role=#{role}&token=token" + find('.js-invitation-role').click - select(I18n.t('invitation_role.mentor')) - find('.js-invitation-course') - select(course.title) - assert_text "http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}/users/new?company_id=#{company.id}&course_id=#{course.id}&role=mentor&token=token" + select(role_text) + Timeout.timeout(Capybara.default_max_wait_time, StandardError) do + loop until find('.js-invitation-url-text').value == expected && find('.js-invitation-url')[:href] == expected + end + end - company = companies(:company2) + test 'change selected course' do + visit_with_auth '/admin/invitation_url', 'komagata' + company = Company.order(created_at: :desc).first + role = User::INVITATION_ROLES.first[1] course = courses(:course2) - find('.js-invitation-company').click - select(company.name) - find('.js-invitation-role').click - select(I18n.t('invitation_role.trainee')) - find('.js-invitation-course') - select(course.title) - assert_text "http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}/users/new?company_id=#{company.id}&course_id=#{course.id}&role=trainee&token=token" + expected = "#{@new_user_url}?company_id=#{company.id}&course_id=#{course.id}&role=#{role}&token=token" - company = companies(:company1) - course = courses(:course1) - find('.js-invitation-company').click - select(company.name) - find('.js-invitation-role').click - select(I18n.t('invitation_role.adviser')) find('.js-invitation-course') select(course.title) - assert_text "http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}/users/new?company_id=#{company.id}&course_id=#{course.id}&role=adviser&token=token" + Timeout.timeout(Capybara.default_max_wait_time, StandardError) do + loop until find('.js-invitation-url-text').value == expected && find('.js-invitation-url')[:href] == expected + end end end From a895a565430bad97724bf19e985bcb3404c83a85 Mon Sep 17 00:00:00 2001 From: naokinaokiboo Date: Mon, 15 Apr 2024 15:05:12 +0900 Subject: [PATCH 10/11] =?UTF-8?q?=E9=87=8D=E8=A4=87=E3=81=97=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=82=8B=E3=83=86=E3=82=B9=E3=83=88=E3=82=B3=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=82=92=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/system/admin/invitation_url_test.rb | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/test/system/admin/invitation_url_test.rb b/test/system/admin/invitation_url_test.rb index ad10c811dfb..2a65457ed21 100644 --- a/test/system/admin/invitation_url_test.rb +++ b/test/system/admin/invitation_url_test.rb @@ -17,6 +17,12 @@ class Admin::InvitationUrlTest < ApplicationSystemTestCase assert_equal '管理ページ | FBC', title end + def wait_for_invitation_url_with_timeout(expected) + Timeout.timeout(Capybara.default_max_wait_time, StandardError) do + loop until find('.js-invitation-url-text').value == expected && find('.js-invitation-url')[:href] == expected + end + end + test 'show invitation-url page' do visit_with_auth '/admin/invitation_url', 'komagata' company = Company.order(created_at: :desc).first @@ -24,9 +30,7 @@ class Admin::InvitationUrlTest < ApplicationSystemTestCase course = Course.order(:created_at).first expected = "#{@new_user_url}?company_id=#{company.id}&course_id=#{course.id}&role=#{role}&token=token" - Timeout.timeout(Capybara.default_max_wait_time, StandardError) do - loop until find('.js-invitation-url-text').value == expected && find('.js-invitation-url')[:href] == expected - end + wait_for_invitation_url_with_timeout(expected) end test 'change selected company' do @@ -38,9 +42,7 @@ class Admin::InvitationUrlTest < ApplicationSystemTestCase find('.js-invitation-company').click select(company.name) - Timeout.timeout(Capybara.default_max_wait_time, StandardError) do - loop until find('.js-invitation-url-text').value == expected && find('.js-invitation-url')[:href] == expected - end + wait_for_invitation_url_with_timeout(expected) end test 'change selected role' do @@ -53,9 +55,7 @@ class Admin::InvitationUrlTest < ApplicationSystemTestCase find('.js-invitation-role').click select(role_text) - Timeout.timeout(Capybara.default_max_wait_time, StandardError) do - loop until find('.js-invitation-url-text').value == expected && find('.js-invitation-url')[:href] == expected - end + wait_for_invitation_url_with_timeout(expected) end test 'change selected course' do @@ -67,8 +67,6 @@ class Admin::InvitationUrlTest < ApplicationSystemTestCase find('.js-invitation-course') select(course.title) - Timeout.timeout(Capybara.default_max_wait_time, StandardError) do - loop until find('.js-invitation-url-text').value == expected && find('.js-invitation-url')[:href] == expected - end + wait_for_invitation_url_with_timeout(expected) end end From ea7a2ca80fb046780e12e1c89ac174101ed784ae Mon Sep 17 00:00:00 2001 From: naokinaokiboo Date: Tue, 28 May 2024 21:15:51 +0900 Subject: [PATCH 11/11] =?UTF-8?q?=E6=8B=9B=E5=BE=85URL=E3=81=AE=E5=A4=89?= =?UTF-8?q?=E6=9B=B4=E3=82=92HTTP=E3=83=AA=E3=82=AF=E3=82=A8=E3=82=B9?= =?UTF-8?q?=E3=83=88=E7=84=A1=E3=81=97=E3=81=A7=E8=A1=8C=E3=81=86=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/invitation_url_controller.rb | 9 ++++++- .../api/admin/invitation_url_controller.rb | 13 --------- app/javascript/invitation-url-updater.js | 27 ++++++++----------- .../admin/invitation_url/index.html.slim | 2 +- config/routes/api.rb | 1 - 5 files changed, 20 insertions(+), 32 deletions(-) delete mode 100644 app/controllers/api/admin/invitation_url_controller.rb diff --git a/app/controllers/admin/invitation_url_controller.rb b/app/controllers/admin/invitation_url_controller.rb index 0a71316f10a..c9def209d74 100644 --- a/app/controllers/admin/invitation_url_controller.rb +++ b/app/controllers/admin/invitation_url_controller.rb @@ -1,5 +1,12 @@ # frozen_string_literal: true class Admin::InvitationUrlController < AdminController - def index; end + def index + @invitation_url_template = new_user_url( + company_id: 'dummy_company_id', + role: 'dummy_role', + course_id: 'dummy_course_id', + token: ENV['TOKEN'] || 'token' + ) + end end diff --git a/app/controllers/api/admin/invitation_url_controller.rb b/app/controllers/api/admin/invitation_url_controller.rb deleted file mode 100644 index 6d99313e684..00000000000 --- a/app/controllers/api/admin/invitation_url_controller.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class API::Admin::InvitationUrlController < API::Admin::BaseController - def index - url = new_user_url( - company_id: params[:company_id], - role: params[:role], - course_id: params[:course_id], - token: ENV['TOKEN'] || 'token' - ) - render json: { url: } - end -end diff --git a/app/javascript/invitation-url-updater.js b/app/javascript/invitation-url-updater.js index c1ea71b0f5c..cd400adb6e0 100644 --- a/app/javascript/invitation-url-updater.js +++ b/app/javascript/invitation-url-updater.js @@ -14,27 +14,22 @@ document.addEventListener('DOMContentLoaded', async () => { const invitationRole = document.querySelector('.js-invitation-role') const invitationCourse = document.querySelector('.js-invitation-course') - const params = new URLSearchParams() - params.append( - 'company_id', + const selectedCompanyId = invitationCompany.options[invitationCompany.selectedIndex].value - ) - params.append( - 'role', + const selectedRole = invitationRole.options[invitationRole.selectedIndex].value - ) - params.append( - 'course_id', + const selectedCourseId = invitationCourse.options[invitationCourse.selectedIndex].value - ) - const response = await fetch( - `/api/admin/invitation_url?${params.toString()}` - ).catch((error) => console.warn(error)) - const json = await response.json().catch((error) => console.warn(error)) + const invitationUrlTemplate = + document.querySelector('.invitation__url').dataset.invitationUrlTemplate + const targetUrl = invitationUrlTemplate + .replace(/company_id=[^&]*/, `company_id=${selectedCompanyId}`) + .replace(/role=[^&]*/, `role=${selectedRole}`) + .replace(/course_id=[^&]*/, `course_id=${selectedCourseId}`) - invitationUrl.href = json.url - invitationUrlText.value = json.url + invitationUrl.href = targetUrl + invitationUrlText.value = targetUrl } invitationElements.forEach((invitationElement) => { diff --git a/app/views/admin/invitation_url/index.html.slim b/app/views/admin/invitation_url/index.html.slim index 099804caeff..2655a742d1d 100644 --- a/app/views/admin/invitation_url/index.html.slim +++ b/app/views/admin/invitation_url/index.html.slim @@ -30,7 +30,7 @@ header.page-header = label_tag :course, 'コース', class: 'a-form-label' .a-button.is-md.is-secondary.is-select.is-block = select_tag :course, options_from_collection_for_select(Course.order(:created_at), :id, :title), class: 'js-invitation-course' - .invitation__url + .invitation__url data-invitation-url-template=@invitation_url_template .a-form-label | URL .invitation__url-inner.flex.gap-1 diff --git a/config/routes/api.rb b/config/routes/api.rb index e3da61d5b89..6a579e547e6 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -5,7 +5,6 @@ namespace 'admin' do resource :count, controller: 'count', only: %i(show) resources :companies, only: %i(index destroy) - resources :invitation_url, only: %i(index) end namespace 'mentor' do resources :practices, only: %i(index)