Skip to content

Commit

Permalink
WIP add buttons for sending vacancy to moderation and to archive
Browse files Browse the repository at this point in the history
  • Loading branch information
Senyarsenie committed Jun 10, 2024
1 parent 7d0c001 commit 8db28f9
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 17 deletions.
15 changes: 9 additions & 6 deletions app/controllers/web/account/vacancies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def update
authorize @vacancy
vacancy = @vacancy.becomes(Web::Account::VacancyForm)
if vacancy.update(params[:vacancy])
change_visibility(@vacancy)
f(:success)
redirect_to account_vacancies_path
else
Expand All @@ -45,11 +44,15 @@ def update
end
end

def destroy; end

private
def archive
vacancy = current_user.vacancies.find params[:id]
vacancy.archive!
end

def change_visibility(vacancy)
vacancy.archive! if params[:archive]
def send_to_moderate
vacancy = current_user.vacancies.find params[:id]
vacancy.send_to_moderate!
end

def destroy; end
end
6 changes: 6 additions & 0 deletions app/views/web/account/vacancies/_actions.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.fs-5 = t('.help')
.row.mt-3
.col-auto.d-flex.mb-3
.me-3 = link_to t('.archive'), archive_account_vacancy_path(vacancy), method: :patch, class: 'btn btn-success', disabled: vacancy.may_archive?, data: { confirm: 'Are you sure?' }
.col-auto.mb-3
.me-3 = link_to t('.send_to_moderate'), send_to_moderate_account_vacancy_path(vacancy), method: :patch, class: 'btn btn-danger', data: { confirm: 'Are you sure?' }, disabled: vacancy.may_send_to_moderate?
8 changes: 3 additions & 5 deletions app/views/web/account/vacancies/_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@
.mb-3
= f.input :direction_list, input_html: { value: f.object.direction_list.to_s }
.row.mt-5
.col-sm.d-flex.mb-3
.me-3 = f.button :submit, class: 'btn-primary'
- if local_assigns.fetch(:show_archive_button, false)
.me-3 = f.button :submit, t('.archive'), data: { confirm: t('confirm') }, class: 'btn-outline-primary', name: 'archive'
.col-sm.d-flex.justify-content-end.mb-3
.col-auto.d-flex.mb-3
= f.button :submit, class: 'btn-primary'
.col-auto.mb-3
= link_to t('.cancel'), url_for(:back), class: 'btn btn-outline-secondary'
3 changes: 2 additions & 1 deletion app/views/web/account/vacancies/edit.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
.alert.alert-secondary
= t('.vacancy_archived')

= render 'form', vacancy: @vacancy, url: account_vacancy_path(@vacancy), show_archive_button: [email protected]?
= render 'form', vacancy: @vacancy, url: account_vacancy_path(@vacancy)
= render 'actions', vacancy: @vacancy, url: account_vacancy_path(@vacancy)
3 changes: 2 additions & 1 deletion app/views/web/account/vacancies/new.html.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- content_for :header do
= t('.header')

= render 'form', vacancy: @vacancy, url: account_vacancies_path, show_archive_button: false
= render 'form', vacancy: @vacancy, url: account_vacancies_path
= render 'actions', vacancy: @vacancy
1 change: 1 addition & 0 deletions config/locales/en.views.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ en:
vacancies:
form:
archive: Archive
send_to_moderate: Send to moderate
cancel: Cancel
new:
header: New vacancy
Expand Down
2 changes: 2 additions & 0 deletions config/locales/ru.helpers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ ru:
submit:
create: Создать
update: Изменить
archive: Архивировать
send_to_moderate: Отправить на модерацию
web_lead_form:
create: Получить консультацию
4 changes: 4 additions & 0 deletions config/locales/ru.views.yml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ ru:
vacancies:
form:
archive: В архив
send_to_moderate: На модерацию
cancel: Отмена
new:
header: Новая вакансия
Expand All @@ -333,6 +334,9 @@ ru:
index:
resume: Ищите кандидатов в разделе Резюме
header: Мои вакансии
actions:
archive: В архив
send_to_moderate: На модерацию
resumes:
new:
info_for_user: Обращаем ваше внимание если вы планируете искать работу в России и СНГ, создавайте резюме в русскоязычной версии сайта
Expand Down
7 changes: 6 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@

namespace :account do
resources :resumes
resources :vacancies
resources :vacancies do
member do
patch :archive
patch :send_to_moderate
end
end
resources :notifications, only: %i[index update]
resource :newsletters, only: %i[edit update]
resource :profile, only: %i[edit update destroy]
Expand Down
20 changes: 17 additions & 3 deletions test/controllers/web/account/vacancies_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,24 @@ class Web::Account::VacanciesControllerTest < ActionDispatch::IntegrationTest
assert { vacancy }
end

test '#edit' do
vacancy = vacancies(:one)
get edit_account_vacancy_path(vacancy)
test '#archive' do
vacancy = vacancies(:state_idle)
patch archive_account_vacancy_path(vacancy)
assert_response :success

vacancy.reload

assert { vacancy.archived? }
end

test '#send_to_moderate' do
vacancy = vacancies(:state_idle)
patch send_to_moderate_account_vacancy_path(vacancy)
assert_response :success

vacancy.reload

assert { vacancy.on_moderate? }
end

test 'can not edit a posted job' do
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/vacancies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,8 @@ over_month_old:
title: Фронтендер
salary_to: 2000
published_at: <%= 2.month.ago.to_fs(:db) %>

state_idle:
<<: *DEFAULTS
title: Черновик
state: idle

0 comments on commit 8db28f9

Please sign in to comment.