Skip to content

Commit b202886

Browse files
committed
save progress
1 parent 9cf1d11 commit b202886

File tree

5 files changed

+108
-87
lines changed

5 files changed

+108
-87
lines changed

app/controllers/job_applications_controller.rb

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class JobApplicationsController < ApplicationController
2-
before_action :set_job_application, only: [:create, :update, :destroy]
2+
before_action :set_job_application, only: [:edit, :update, :destroy]
33

44
def index
55
@job_applications = filter_and_sort_job_applications
@@ -22,33 +22,50 @@ def index
2222

2323
def new
2424
@job_application = JobApplication.new
25+
respond_to do |format|
26+
format.html
27+
format.turbo_stream { render turbo_stream: turbo_stream.replace("new_job_application", partial: "form", locals: {job_application: @job_application, title: "New"}) }
28+
end
29+
end
30+
31+
def edit
32+
@job_application = JobApplication.find_by(id: params[:id])
33+
if @job_application.nil?
34+
Rails.logger.error "Job Application with id #{params[:id]} not found"
35+
redirect_to root_path, alert: "Job Application not found"
36+
end
2537
end
2638

2739
def create
2840
@job_application = JobApplication.new(job_application_params)
2941

3042
respond_to do |format|
3143
if @job_application.save
32-
format.html { redirect_to job_applications_path, notice: "Job application was successfully created." }
44+
format.html { redirect_to root_path, notice: "Job application was successfully created." }
3345
format.turbo_stream {
3446
flash.now[:notice] = "Job application was successfully created."
3547
render turbo_stream: [
3648
turbo_stream.prepend("job_applications", partial: "job_application", locals: {job_application: @job_application}),
37-
turbo_stream.update("flash_messages", partial: "flash_messages"),
38-
turbo_stream.replace("new_job_application", partial: "form", locals: {job_application: JobApplication.new})
49+
turbo_stream.update("job_application_count", JobApplication.count),
50+
turbo_stream.update("flash_messages", partial: "flash_messages")
3951
]
4052
}
4153
else
4254
format.html { render :new, status: :unprocessable_entity }
43-
format.turbo_stream { render turbo_stream: turbo_stream.replace(@job_application, partial: "form", locals: {job_application: @job_application}) }
55+
format.turbo_stream {
56+
render turbo_stream: [
57+
turbo_stream.replace("new_job_application", partial: "form", locals: {job_application: @job_application, title: "New"}),
58+
turbo_stream.update("flash_messages", partial: "flash_messages")
59+
]
60+
}
4461
end
4562
end
4663
end
4764

4865
def update
4966
respond_to do |format|
5067
if @job_application.update(job_application_params)
51-
format.html { redirect_to job_applications_path, notice: "Job application was successfully updated." }
68+
format.html { redirect_to root_path, notice: "Job application was successfully updated." }
5269
format.turbo_stream {
5370
flash.now[:notice] = "Job application was successfully updated."
5471
render turbo_stream: [
@@ -58,15 +75,20 @@ def update
5875
}
5976
else
6077
format.html { render :edit, status: :unprocessable_entity }
61-
format.turbo_stream { render turbo_stream: turbo_stream.replace(@job_application, partial: "form", locals: {job_application: @job_application}) }
78+
format.turbo_stream {
79+
render turbo_stream: [
80+
turbo_stream.replace(dom_id(@job_application), partial: "form", locals: {job_application: @job_application, title: "Edit"}),
81+
turbo_stream.update("flash_messages", partial: "flash_messages")
82+
]
83+
}
6284
end
6385
end
6486
end
6587

6688
def destroy
6789
@job_application.destroy
6890
respond_to do |format|
69-
format.html { redirect_to job_applications_url, notice: "Job application was successfully deleted." }
91+
format.html { redirect_to root_path, notice: "Job application was successfully deleted." }
7092
format.turbo_stream {
7193
flash.now[:notice] = "Job application was successfully deleted."
7294
render turbo_stream: [
Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,63 @@
11
<%= turbo_frame_tag dom_id(job_application) do %>
2-
<%= form_with(model: job_application, local: false) do |form| %>
3-
<% if job_application.errors.any? %>
4-
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-4" role="alert">
5-
<strong class="font-bold">Error:</strong>
6-
<span class="block sm:inline"><%= pluralize(job_application.errors.count, "error") %> prohibited this job application from being saved:</span>
7-
<ul class="list-disc list-inside">
8-
<% job_application.errors.full_messages.each do |message| %>
9-
<li><%= message %></li>
2+
<div class="flex justify-center items-center w-full max-h-screen p-2 md:p-4">
3+
<div class="w-full md:w-[800px] bg-white shadow-lg rounded-lg overflow-hidden">
4+
<div class="px-4 md:px-8 py-3 md:py-6 bg-gray-50 border-b border-gray-200">
5+
<h2 class="text-2xl font-bold text-gray-900"><%= "#{title} Job Application" %></h2>
6+
<p class="mt-1 text-sm text-gray-600">Please fill in the relevant details of your recent job application.</p>
7+
</div>
8+
<div class="px-8 py-6">
9+
<%= form_with(model: job_application, local: false, class: "space-y-6") do |form| %>
10+
<% if job_application.errors.any? %>
11+
<div class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4 mb-4" role="alert">
12+
<p class="font-bold">Error:</p>
13+
<p><%= pluralize(job_application.errors.count, "error") %> prohibited this job application from being saved:</p>
14+
<ul class="list-disc list-inside">
15+
<% job_application.errors.full_messages.each do |message| %>
16+
<li><%= message %></li>
17+
<% end %>
18+
</ul>
19+
</div>
1020
<% end %>
11-
</ul>
21+
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
22+
<div>
23+
<%= form.label :date_applied, class: 'block text-sm font-medium text-gray-700 mb-2' %>
24+
<%= form.date_field :date_applied, class: 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline' %>
25+
</div>
26+
<div>
27+
<%= form.label :company_name, class: 'block text-sm font-medium text-gray-700 mb-2' %>
28+
<%= form.text_field :company_name, class: 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline' %>
29+
</div>
30+
<div>
31+
<%= form.label :method_of_contact, class: 'block text-sm font-medium text-gray-700 mb-2' %>
32+
<%= form.select :method_of_contact, JobApplication.method_of_contacts.keys.map { |k| [k.humanize, k] }, { include_blank: 'Select a method' }, class: 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline' %>
33+
</div>
34+
<div>
35+
<%= form.label :email_address, class: 'block text-sm font-medium text-gray-700 mb-2' %>
36+
<%= form.email_field :email_address, class: 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline' %>
37+
</div>
38+
<div>
39+
<%= form.label :point_of_contact, class: 'block text-sm font-medium text-gray-700 mb-2' %>
40+
<%= form.text_field :point_of_contact, class: 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline' %>
41+
</div>
42+
<div>
43+
<%= form.label :website_link, class: 'block text-sm font-medium text-gray-700 mb-2' %>
44+
<%= form.url_field :website_link, class: 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline' %>
45+
</div>
46+
<div>
47+
<%= form.label :position_type, class: 'block text-sm font-medium text-gray-700 mb-2' %>
48+
<%= form.select :position_type, JobApplication.position_types.keys.map { |k| [k.humanize, k] }, { include_blank: 'Select a type' }, class: 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline' %>
49+
</div>
50+
<div>
51+
<%= form.label :position_title, class: 'block text-sm font-medium text-gray-700 mb-2' %>
52+
<%= form.text_field :position_title, class: 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline' %>
53+
</div>
54+
</div>
55+
<div class="flex items-center justify-end mt-6">
56+
<%= link_to 'Cancel', root_path, class: 'bg-gray-500 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline mr-2', data: { turbo_frame: "_top" } %>
57+
<%= form.submit "Save", class: 'bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline' %>
58+
</div>
59+
<% end %>
1260
</div>
13-
<% end %>
14-
<div class="mb-4">
15-
<%= form.label :date_applied, class: 'block text-gray-700 text-sm font-bold mb-2' %>
16-
<%= form.date_field :date_applied, class: 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline' %>
17-
</div>
18-
<div class="mb-4">
19-
<%= form.label :company_name, class: 'block text-gray-700 text-sm font-bold mb-2' %>
20-
<%= form.text_field :company_name, class: 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline' %>
21-
</div>
22-
<div class="mb-4">
23-
<%= form.label :method_of_contact, class: 'block text-gray-700 text-sm font-bold mb-2' %>
24-
<%= form.select :method_of_contact, JobApplication.method_of_contacts.keys.map { |k| [k.humanize, k] }, { include_blank: 'Select a method' }, class: 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline' %>
25-
</div>
26-
<div class="mb-4">
27-
<%= form.label :email_address, class: 'block text-gray-700 text-sm font-bold mb-2' %>
28-
<%= form.email_field :email_address, class: 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline' %>
29-
</div>
30-
<div class="mb-4">
31-
<%= form.label :point_of_contact, class: 'block text-gray-700 text-sm font-bold mb-2' %>
32-
<%= form.text_field :point_of_contact, class: 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline' %>
33-
</div>
34-
<div class="mb-4">
35-
<%= form.label :website_link, class: 'block text-gray-700 text-sm font-bold mb-2' %>
36-
<%= form.url_field :website_link, class: 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline' %>
37-
</div>
38-
<div class="mb-4">
39-
<%= form.label :position_type, class: 'block text-gray-700 text-sm font-bold mb-2' %>
40-
<%= form.select :position_type, JobApplication.position_types.keys.map { |k| [k.humanize, k] }, { include_blank: 'Select a type' }, class: 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline' %>
41-
</div>
42-
<div class="mb-6">
43-
<%= form.label :position_title, class: 'block text-gray-700 text-sm font-bold mb-2' %>
44-
<%= form.text_field :position_title, class: 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline' %>
45-
</div>
46-
<div class="flex items-center justify-between">
47-
<%= form.submit class: 'bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline cursor-pointer' %>
48-
<%= link_to 'Back', root_path, class: 'inline-block align-baseline font-bold text-sm text-blue-500 hover:text-blue-800' %>
4961
</div>
50-
<% end %>
62+
</div>
5163
<% end %>
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
11
<%= turbo_frame_tag dom_id(@job_application) do %>
2-
<div class="container mx-auto px-4 py-8">
3-
<div class="mb-4">
4-
<h2 class="text-2xl font-semibold text-gray-700">Edit Job Application</h2>
5-
</div>
6-
<%= render 'form', job_application: @job_application %>
7-
<%= link_to 'Back', root_path, class: 'inline-block align-baseline font-bold text-sm text-blue-500 hover:text-blue-800' %>
8-
<%= link_to 'Back to Job Applications', job_applications_path, class: 'mt-4 inline-block text-blue-500 hover:text-blue-700' %>
9-
</div>
2+
<%= render 'form', job_application: @job_application, title: "Edit" %>
103
<% end %>

app/views/job_applications/index.html.erb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
<div class="container mx-auto px-4 py-8">
2-
<%= turbo_frame_tag "flash_messages" do %>
3-
<%= render 'flash_messages' %>
4-
<% end %>
1+
<div class="my-2 md:my-8">
52
<div class="mb-8 flex justify-between items-center">
63
<h2 class="hidden md:block md:text-2xl font-semibold text-gray-700 shadow-2xl">
74
Job Tracker
85
</h2>
9-
<%= link_to 'Add New Job Application', new_job_application_path, class: 'text-sm bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded cursor-pointer', data: { turbo_frame: "_top" } %>
6+
<%= link_to 'New Job Application', new_job_application_path, class: 'text-sm bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded cursor-pointer', data: { turbo_frame: "_top" } %>
107
</div>
118
<%= form_with url: job_applications_path, method: :get, data: { controller: "job-filter", turbo_frame: "job_applications_table" } do |form| %>
129
<div class="flex flex-wrap -mx-2 mb-4">
1310
<div class="w-full md:w-1/4 px-2 mb-4 md:mb-0">
11+
<%= form.label :search, "Search", class: "sr-only" %>
1412
<%= form.text_field :search, value: params[:search], class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline", placeholder: "Search by company or position", data: { action: "input->job-filter#submit" } %>
1513
</div>
1614
<div class="w-full md:w-1/4 px-2 mb-4 md:mb-0">
15+
<%= form.label :method_of_contact, "Contact Method", class: "sr-only" %>
1716
<%= form.select :method_of_contact,
18-
options_for_select([["All Contact Methods", ""]] + JobApplication.method_of_contacts.map { |k, v| [k.humanize, v] }, params[:method_of_contact]),
19-
{},
20-
class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline",
21-
data: { action: "change->job-filter#submit" }
22-
%>
17+
options_for_select([["All Contact Methods", ""]] + JobApplication.method_of_contacts.map { |k, v| [k.humanize, v] }, params[:method_of_contact]),
18+
{},
19+
class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline",
20+
data: { action: "change->job-filter#submit" }
21+
%>
2322
</div>
2423
<div class="w-full md:w-1/4 px-2">
24+
<%= form.label :position_type, "Position Type", class: "sr-only" %>
2525
<%= form.select :position_type,
26-
options_for_select([["All Position Types", ""]] + JobApplication.position_types.map { |k, v| [k.humanize, v] }, params[:position_type]),
27-
{},
28-
class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline",
29-
data: { action: "change->job-filter#submit" }
30-
%>
26+
options_for_select([["All Position Types", ""]] + JobApplication.position_types.map { |k, v| [k.humanize, v] }, params[:position_type]),
27+
{},
28+
class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline",
29+
data: { action: "change->job-filter#submit" }
30+
%>
3131
</div>
3232
<div class="w-full md:w-1/4 px-2 mt-4 md:mt-0">
33-
<%= form.button "Reset Filters", type: "button", class: "w-full bg-gray-400 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded cursor-pointer", data: { action: "click->job-filter#reset" } %>
33+
<%= form.button "Reset Filters", type: "button", class: "w-full bg-gray-600 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded cursor-pointer", data: { action: "click->job-filter#reset" } %>
3434
</div>
3535
</div>
3636
<% end %>
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
<div class="container mx-auto px-4 py-8">
2-
<div class="mb-4">
3-
<h2 class="text-2xl font-semibold text-gray-700">New Job Application</h2>
4-
</div>
5-
<%= turbo_frame_tag "new_job_application" do %>
6-
<%= render 'form', job_application: @job_application %>
7-
<% end %>
8-
<%= link_to 'Back to Job Applications', job_applications_path, class: 'mt-4 inline-block text-blue-500 hover:text-blue-700' %>
9-
</div>
1+
<%= turbo_frame_tag "new_job_application" do %>
2+
<%= render 'form', job_application: @job_application, title: "New" %>
3+
<% end %>

0 commit comments

Comments
 (0)