-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7542 from fjordllc/feature/add-invitation-url-page
招待URL作成ページを追加
- Loading branch information
Showing
10 changed files
with
181 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class Admin::InvitationUrlController < AdminController | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
document.addEventListener('DOMContentLoaded', async () => { | ||
const invitationElements = Array.from( | ||
document.querySelectorAll('.invitation__element select') | ||
) | ||
const invitationUrl = document.querySelector('.js-invitation-url') | ||
const invitationUrlText = document.querySelector('.js-invitation-url-text') | ||
|
||
if (invitationElements.length === 0 || !invitationUrlText || !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 selectedCompanyId = | ||
invitationCompany.options[invitationCompany.selectedIndex].value | ||
const selectedRole = | ||
invitationRole.options[invitationRole.selectedIndex].value | ||
const selectedCourseId = | ||
invitationCourse.options[invitationCourse.selectedIndex].value | ||
|
||
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 = targetUrl | ||
invitationUrlText.value = targetUrl | ||
} | ||
|
||
invitationElements.forEach((invitationElement) => { | ||
invitationElement.addEventListener('change', updateInvitationURL) | ||
}) | ||
|
||
window.addEventListener('pageshow', updateInvitationURL) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
- 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.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 data-invitation-url-template=@invitation_url_template | ||
.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# frozen_string_literal: true | ||
|
||
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 'admin can be visited invitation-url page' do | ||
visit_with_auth '/admin/invitation_url', 'komagata' | ||
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 | ||
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" | ||
|
||
wait_for_invitation_url_with_timeout(expected) | ||
end | ||
|
||
test 'change selected company' do | ||
visit_with_auth '/admin/invitation_url', 'komagata' | ||
company = companies(:company3) | ||
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) | ||
wait_for_invitation_url_with_timeout(expected) | ||
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(role_text) | ||
wait_for_invitation_url_with_timeout(expected) | ||
end | ||
|
||
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) | ||
expected = "#{@new_user_url}?company_id=#{company.id}&course_id=#{course.id}&role=#{role}&token=token" | ||
|
||
find('.js-invitation-course') | ||
select(course.title) | ||
wait_for_invitation_url_with_timeout(expected) | ||
end | ||
end |