Skip to content

Commit fc067dc

Browse files
committed
save
1 parent 1ee2363 commit fc067dc

File tree

7 files changed

+83
-19
lines changed

7 files changed

+83
-19
lines changed

app/controllers/job_applications_controller.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class JobApplicationsController < ApplicationController
44
def index
55
@job_applications = filter_and_sort_job_applications
66
@job_application_count = @job_applications.count
7-
@job_applications = @job_applications.paginate(page: params[:page], per_page: 10)
7+
@job_applications = @job_applications.paginate(page: params[:page], per_page: 10).order(created_at: :desc)
88

99
@pagination_info = {
1010
current_page: @job_applications.current_page,
@@ -29,10 +29,9 @@ def new
2929
end
3030

3131
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"
32+
respond_to do |format|
33+
format.html
34+
format.turbo_stream { render turbo_stream: turbo_stream.replace(dom_id(@job_application), partial: "form", locals: {job_application: @job_application, title: "Edit"}) }
3635
end
3736
end
3837

@@ -104,6 +103,8 @@ def destroy
104103

105104
def set_job_application
106105
@job_application = JobApplication.find(params[:id])
106+
rescue ActiveRecord::RecordNotFound
107+
redirect_to root_path, alert: "Job application not found."
107108
end
108109

109110
def job_application_params

app/frontend/controllers/flash_message_controller.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@ export default class extends Controller {
1010
show() {
1111
this.element.classList.remove('hidden');
1212
setTimeout(() => {
13-
this.element.classList.add('hidden');
14-
}, 5000);
13+
this.fadeOut();
14+
}, 2000); // Start fading out after 4 seconds
15+
}
16+
17+
fadeOut() {
18+
const flashMessage = this.element.querySelector('.flash-message');
19+
if (flashMessage) {
20+
flashMessage.classList.add('fade-out');
21+
setTimeout(() => {
22+
this.element.classList.add('hidden');
23+
}, 500); // Duration of fade-out animation
24+
}
1525
}
1626
}

app/helpers/application_helper.rb

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
module ApplicationHelper
22
def flash_class(type)
3+
base_class = "border-l-4 p-4 mb-4 rounded-md"
34
case type.to_sym
4-
when :notice then "bg-blue-100 border-blue-500 text-blue-700"
5-
when :success then "bg-green-100 border-green-500 text-green-700"
6-
when :error then "bg-red-100 border-red-500 text-red-700"
7-
when :alert then "bg-yellow-100 border-yellow-500 text-yellow-700"
8-
else "bg-gray-100 border-gray-500 text-gray-700"
9-
end + " border-l-4 p-4 mb-4"
5+
when :notice
6+
"bg-blue-100 border-blue-500 text-blue-700 #{base_class}"
7+
when :success
8+
"bg-green-100 border-green-500 text-green-700 #{base_class}"
9+
when :error
10+
"bg-red-100 border-red-500 text-red-700 #{base_class}"
11+
when :alert
12+
"bg-yellow-100 border-yellow-500 text-yellow-700 #{base_class}"
13+
else
14+
"bg-gray-100 border-gray-500 text-gray-700 #{base_class}"
15+
end
16+
end
17+
18+
def progress_bar_class(type)
19+
base_class = "rounded-md"
20+
case type.to_sym
21+
when :notice
22+
"bg-blue-500 #{base_class}"
23+
when :success
24+
"bg-green-500 #{base_class}"
25+
when :error
26+
"bg-red-500 #{base_class}"
27+
when :alert
28+
"bg-yellow-500 #{base_class}"
29+
else
30+
"bg-gray-500 #{base_class}"
31+
end
1032
end
1133

1234
def sort_link_to(name, column)

app/views/application/_flash_messages.html.erb

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
1-
<div data-controller="flash-message" class="hidden">
1+
<style>
2+
@keyframes flash-progress {
3+
from {
4+
width: 100%;
5+
left: 0;
6+
}
7+
to {
8+
width: 0;
9+
left: 0;
10+
}
11+
}
12+
13+
@keyframes fade-out {
14+
from {
15+
opacity: 1;
16+
}
17+
to {
18+
opacity: 0;
19+
}
20+
}
21+
22+
.flash-progress-bar {
23+
animation: flash-progress 2s linear forwards;
24+
}
25+
26+
.flash-message.fade-out {
27+
animation: fade-out 0.5s forwards;
28+
}
29+
</style>
30+
<div data-controller="flash-message" class="hidden relative">
231
<% flash.each do |type, message| %>
3-
<div class="<%= flash_class(type) %>" role="alert">
32+
<div class="<%= flash_class(type) %> flash-message relative" role="alert">
33+
<div class="flash-progress-bar absolute top-0 left-0 h-1 w-full <%= progress_bar_class(type) %>"></div>
434
<%= message %>
535
</div>
636
<% end %>

app/views/job_applications/_form.html.erb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
<div class="px-8 py-6">
99
<%= form_with(model: job_application, local: false, class: "space-y-6") do |form| %>
1010
<% 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>
11+
<div class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4 mb-4 rounded-md" role="alert">
12+
<p><%= pluralize(job_application.errors.count, "error") %></p>
1413
<ul class="list-disc list-inside">
1514
<% job_application.errors.full_messages.each do |message| %>
1615
<li><%= message %></li>

app/views/job_applications/index.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
<div id="flash_messages">
2+
<%= render 'flash_messages' %>
3+
</div>
14
<div class="my-2 md:my-8">
25
<div class="mb-8 flex justify-between items-center">
36
<h2 class="hidden md:block md:text-2xl font-semibold text-gray-700 shadow-2xl">

app/views/layouts/application.html.erb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
</head>
1313
<body class="bg-gray-100">
1414
<div class="container mx-auto px-4 py-4">
15-
<%= render 'flash_messages' %>
1615
<%= yield %>
1716
</div>
1817
</body>

0 commit comments

Comments
 (0)