diff --git a/app/controllers/web/account/vacancies_controller.rb b/app/controllers/web/account/vacancies_controller.rb index ae721b4e..9dfb3d86 100644 --- a/app/controllers/web/account/vacancies_controller.rb +++ b/app/controllers/web/account/vacancies_controller.rb @@ -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 @@ -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 diff --git a/app/views/web/account/vacancies/_actions.html.slim b/app/views/web/account/vacancies/_actions.html.slim new file mode 100644 index 00000000..ab31f9d3 --- /dev/null +++ b/app/views/web/account/vacancies/_actions.html.slim @@ -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? diff --git a/app/views/web/account/vacancies/_form.html.slim b/app/views/web/account/vacancies/_form.html.slim index 99efbbce..3d123aa9 100644 --- a/app/views/web/account/vacancies/_form.html.slim +++ b/app/views/web/account/vacancies/_form.html.slim @@ -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' diff --git a/app/views/web/account/vacancies/edit.html.slim b/app/views/web/account/vacancies/edit.html.slim index aae4b3c3..cdef3b8f 100644 --- a/app/views/web/account/vacancies/edit.html.slim +++ b/app/views/web/account/vacancies/edit.html.slim @@ -5,4 +5,5 @@ .alert.alert-secondary = t('.vacancy_archived') -= render 'form', vacancy: @vacancy, url: account_vacancy_path(@vacancy), show_archive_button: !@vacancy.archived? += render 'form', vacancy: @vacancy, url: account_vacancy_path(@vacancy) += render 'actions', vacancy: @vacancy, url: account_vacancy_path(@vacancy) diff --git a/app/views/web/account/vacancies/new.html.slim b/app/views/web/account/vacancies/new.html.slim index 40f857f1..f9513ef1 100644 --- a/app/views/web/account/vacancies/new.html.slim +++ b/app/views/web/account/vacancies/new.html.slim @@ -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 diff --git a/config/locales/en.views.yml b/config/locales/en.views.yml index e4c11df6..8c39990a 100644 --- a/config/locales/en.views.yml +++ b/config/locales/en.views.yml @@ -226,6 +226,7 @@ en: vacancies: form: archive: Archive + send_to_moderate: Send to moderate cancel: Cancel new: header: New vacancy diff --git a/config/locales/ru.helpers.yml b/config/locales/ru.helpers.yml index 2f403a83..d44cc2e4 100644 --- a/config/locales/ru.helpers.yml +++ b/config/locales/ru.helpers.yml @@ -3,5 +3,7 @@ ru: submit: create: Создать update: Изменить + archive: Архивировать + send_to_moderate: Отправить на модерацию web_lead_form: create: Получить консультацию diff --git a/config/locales/ru.views.yml b/config/locales/ru.views.yml index 4e2d81a4..c1085f84 100644 --- a/config/locales/ru.views.yml +++ b/config/locales/ru.views.yml @@ -324,6 +324,7 @@ ru: vacancies: form: archive: В архив + send_to_moderate: На модерацию cancel: Отмена new: header: Новая вакансия @@ -333,6 +334,9 @@ ru: index: resume: Ищите кандидатов в разделе Резюме header: Мои вакансии + actions: + archive: В архив + send_to_moderate: На модерацию resumes: new: info_for_user: Обращаем ваше внимание если вы планируете искать работу в России и СНГ, создавайте резюме в русскоязычной версии сайта diff --git a/config/routes.rb b/config/routes.rb index 9e724d16..ccf98ec3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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] diff --git a/test/controllers/web/account/vacancies_controller_test.rb b/test/controllers/web/account/vacancies_controller_test.rb index 14b1e728..c300c3d9 100644 --- a/test/controllers/web/account/vacancies_controller_test.rb +++ b/test/controllers/web/account/vacancies_controller_test.rb @@ -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 diff --git a/test/fixtures/vacancies.yml b/test/fixtures/vacancies.yml index 14e3e3fd..c7c40163 100644 --- a/test/fixtures/vacancies.yml +++ b/test/fixtures/vacancies.yml @@ -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