-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setup basic route/view/controller for mentee application states #447
Open
JoshDevHub
wants to merge
11
commits into
main
Choose a base branch
from
setup-routes-for-mentee-application-state
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a68ec8d
setup logic to get past & future states
Natblow 9c79f60
setup routes, controller, skeleton view
Natblow 02dca91
Add MenteeApplicationState model spec
Natblow b7fbd02
Link to state instead of application on application index
JoshDevHub 433a948
Basic style adjustments on states show page
JoshDevHub f36b81b
Add applicant-side text for application_received state
JoshDevHub f245754
Merge branch 'main' into setup-routes-for-mentee-application-state
JoshDevHub f2a9194
Revert i18n file because switching to partial strategy
JoshDevHub 8c1cb01
Rename coding_challenge status key
JoshDevHub f36ee74
Reimplement application received content as a partial
JoshDevHub daec3b6
Add partials for each state of the application process
JoshDevHub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 3 additions & 1 deletion
4
app/components/user_mentee_application/list_item_component.html.erb
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<li class="border-2 flex flex-col p-4 mb-8 gap-2 shadow-lg"> | ||
<%= link_to link_text, mentee_application, class: 'font-bold text-lg text-secondary underline hover:no-underline' %> | ||
<%= link_to link_text, | ||
user_mentee_application_mentee_application_state_path(user_mentee_application_id: mentee_application.id, status_name: mentee_application.current_state), | ||
class: 'font-bold text-lg text-secondary underline hover:no-underline' %> | ||
<p>Status: <%= mentee_application.status.humanize %></p> | ||
<p>Submitted: <%= mentee_application.created_at.to_fs(:slash_format) %></p> | ||
</li> |
38 changes: 6 additions & 32 deletions
38
app/controllers/user_mentee_applications/mentee_application_states_controller.rb
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 |
---|---|---|
@@ -1,42 +1,16 @@ | ||
class UserMenteeApplications::MenteeApplicationStatesController < ApplicationController | ||
before_action :load_user_mentee_application | ||
before_action -> { authorize :user_only, :application_reviewer? } | ||
skip_before_action :only_authorize_agent | ||
|
||
def new; end | ||
|
||
# rubocop:disable Metrics/AbcSize | ||
def create | ||
respond_to do |format| | ||
MenteeApplicationTransitionService.call( | ||
application: @user_mentee_application, | ||
reviewer: current_user, | ||
action: application_state_params[:reviewer_action].to_sym, | ||
note: application_state_params[:note] | ||
) | ||
@user_mentee_application.reload | ||
format.html { redirect_to user_mentee_applications_path } | ||
format.turbo_stream do | ||
flash.now[:notice] = "Application updated to #{@user_mentee_application.current_state.status.humanize.downcase}" | ||
end | ||
rescue MenteeApplicationTransitionService::InvalidTransitionError => e | ||
format.html do | ||
redirect_to new_user_mentee_applications_mentee_application_state_path(@user_mentee_application), | ||
alert: e.message | ||
end | ||
format.turbo_stream { flash.now[:alert] = e.message } | ||
end | ||
def show | ||
@state = @user_mentee_application.mentee_application_states.find_by!(status: params[:status_name]) | ||
@previous_state = @state.previous_state | ||
@next_state = @state.next_state | ||
end | ||
# rubocop:enable Metrics/AbcSize | ||
|
||
private | ||
|
||
def load_user_mentee_application | ||
@user_mentee_application = UserMenteeApplication.find(params[:user_mentee_application_id]) | ||
end | ||
|
||
def application_state_params | ||
params | ||
.permit(:reviewer_action, :note) | ||
.merge(status_changed_id: current_user.id) | ||
@user_mentee_application = current_user.mentee_applications.find(params[:user_mentee_application_id]) | ||
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
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
22 changes: 22 additions & 0 deletions
22
app/views/user_mentee_applications/mentee_application_states/show.html.erb
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,22 @@ | ||
<div class="text-center"> | ||
<h1 class="text-xl font-bold"><%= current_user.full_name %></h1> | ||
<h2 class="text-lg">Application Status</h2> | ||
</div> | ||
|
||
<div class="text-center"> | ||
<% if @previous_state.present? %> | ||
<p>The previous state is <%= link_to @previous_state.status.humanize, user_mentee_application_mentee_application_state_path(user_mentee_application_id: @user_mentee_application.id, status_name: @previous_state) %></p> | ||
<% end %> | ||
|
||
<p>Current State: <%= @state.status.humanize %></p> | ||
|
||
<% if @next_state.present? %> | ||
<p>The next state is <%= link_to @next_state.status.humanize, user_mentee_application_mentee_application_state_path(user_mentee_application_id: @user_mentee_application.id, status_name: @next_state) %></p> | ||
<% else %> | ||
<p>The next state is <%= @state.future_state.to_s.humanize %></p> | ||
<% end %> | ||
</div> | ||
|
||
<div class="p-2 max-w-prose mx-auto"> | ||
<%= t("#{@state.status}.applicant_information").html_safe %> | ||
</div> |
17 changes: 17 additions & 0 deletions
17
config/locales/views/user_mentee_applications/mentee_application_states/en.yml
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,80 @@ | ||
# == Schema Information | ||
# | ||
# Table name: mentee_application_states | ||
# | ||
# id :bigint not null, primary key | ||
# note :text | ||
# status :integer default("application_received"), not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# status_changed_id :bigint | ||
# user_mentee_application_id :bigint not null | ||
# | ||
# Indexes | ||
# | ||
# index_mentee_application_states_on_status_changed_id (status_changed_id) | ||
# index_mentee_application_states_on_user_mentee_application_id (user_mentee_application_id) | ||
# | ||
# Foreign Keys | ||
# | ||
# fk_rails_... (status_changed_id => users.id) | ||
# fk_rails_... (user_mentee_application_id => user_mentee_applications.id) | ||
require 'rails_helper' | ||
|
||
RSpec.describe MenteeApplicationState do | ||
let(:user) { create(:user) } | ||
let(:mentee_application) { create(:user_mentee_application) } | ||
let(:mentee_application_state) { create(:mentee_application_state, user_mentee_application: mentee_application) } | ||
|
||
context 'when status is application received' do | ||
describe 'future_state' do | ||
it 'returns the future state as coding challenge sent' do | ||
expect(mentee_application_state.future_state).to eq(:coding_challenge_sent) | ||
end | ||
end | ||
|
||
describe 'next_state' do | ||
it 'returns the next state as nil' do | ||
expect(mentee_application_state.next_state).to be_nil | ||
end | ||
end | ||
|
||
describe 'previous_state' do | ||
it 'returns the current state' do | ||
expect(mentee_application_state.previous_state.status.to_sym).to eq(:application_received) | ||
end | ||
end | ||
end | ||
|
||
context 'when status is coding challenge sent' do | ||
let(:mentee_application_state) do | ||
create(:mentee_application_state, :coding_challenge_sent, user_mentee_application: mentee_application) | ||
end | ||
|
||
describe 'future_state' do | ||
it 'returns the future state as coding_challenge_received' do | ||
expect(mentee_application_state.future_state).to eq(:coding_challenge_received) | ||
end | ||
end | ||
|
||
describe 'next_state' do | ||
it 'returns the next state as coding_challenge_completed' do | ||
expect(mentee_application_state.next_state).to be_nil | ||
end | ||
|
||
context 'when the user is on application_received state' do | ||
let(:previous_mentee_application_state) { mentee_application_state.previous_state } | ||
|
||
it 'returns the next state as coding_challenge_sent' do | ||
expect(previous_mentee_application_state.next_state.status.to_sym).to eq(:coding_challenge_sent) | ||
end | ||
end | ||
end | ||
|
||
describe 'previous_state' do | ||
it 'returns the previous state as application_received' do | ||
expect(mentee_application_state.previous_state.status.to_sym).to eq(:application_received) | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These methods could arguably go on the
user_mentee_application
, but it'd have to accept a parameter for the state. This is one thing I'm not too sure about.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are fine for now