Skip to content
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

Fix user registration + auto-hide error/notice messages from the UI #96

Merged
merged 7 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ staging: ## Set RAILS_ENV=staging
production: ## Set RAILS_ENV=production
@echo 'export RAILS_ENV=production' > $(MAKE_ENV)

boot: ## Boots Rails sserver in the whatever RAILS_ENV is set to — eg: make production boot
setup: ## Boots Rails sserver in the whatever RAILS_ENV is set to — eg: make production boot
bash bin/boot-up

docker-image: ## Builds a docker image named 'tickets'
Expand All @@ -71,24 +71,32 @@ shellcheck: ## Run shellcheck on the shell files
dev-install: ## Optional install of VIM configuration and other dev tools
$(CURRENT_DIR)/development/dev-install

rebuild-dev-db: development ## Rebuild and re-seed the dev database
@printf "\n$(bg_purple) 👉 $(purple)$(clear) $(yellow)Dropping dev database $(DEV_DB)...$(clear)\n"
# Rails Commands Macros

db-drop: ## Drop current databases
@printf "\n$(bg_purple) 👉 $(purple)$(clear) $(yellow)Dropping dev database [$(DEV_DB)]$(clear)\n"
@dropdb $(DEV_DB) || true
@printf "\n$(bg_purple) 👉 $(purple)$(clear) $(yellow)Creating dev database...$(clear)\n"
@rails db:create
@printf "\n$(bg_purple) 👉 $(purple)$(clear) $(yellow)Migrating dev database...$(clear)\n"
@rails db:migrate
@printf "\n$(bg_purple) 👉 $(purple)$(clear) $(yellow)Seeding dev database...$(clear)\n"
rails db:seed

assets: ## Build JS & CSS assets

db-create: node_modules ## Create if necessary, migrate and seed the database
@printf "\n$(bg_purple) 👉 $(purple)$(clear) $(yellow)Creating Database: [$(DEV_DB)]$(clear)\n"
@bin/rails db:create
@printf "\n$(bg_purple) 👉 $(purple)$(clear) $(yellow)Migrating Databases: [$(DEV_DB)]$(clear)\n"
@bin/rails db:migrate
@printf "\n$(bg_purple) 👉 $(purple)$(clear) $(yellow)Seeding dev database: [$(DEV_DB)]$(clear)\n"
@bin/rails db:seed

rebuild-dev-db: db-drop development db-create ## Rebuild and re-seed the dev database

node_modules: ## Install all Node Modules
@yarn install

assets: node_modules ## Build JS & CSS assets
@yarn run build
@yarn run build:css

dev: development assets ## Start the development environment
@bash -c "source $(MAKE_ENV); bundle exec foreman start -f Procfile.dev"

dev: node_modules db-create ## Start the development environment
@printf "\n$(bg_purple) 👉 $(purple)$(clear) $(yellow)Starting up Foreman in ENV=[$(MAKE_ENV)], db=[$(DEV_DB)]$(clear)\n"
@bash -c "source $(MAKE_ENV); foreman start -f Procfile.dev"

ci: ## Run all tests and linters as if on CI
bin/rails db:migrate
Expand Down
4 changes: 2 additions & 2 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# vim: ft=yaml
web: env RUBY_DEBUG_OPEN=true bin/rails server -p 3000
web: env RUBY_DEBUG_OPEN=true bin/rails server -p 5000
kigster marked this conversation as resolved.
Show resolved Hide resolved
js: yarn watch:js
css: yarn watch:css
browser: sleep 10 && open http://localhost:3000/ && while true; do sleep 100; echo .; done
browser: sleep 10 && open http://localhost:5000/ && while true; do sleep 100; echo .; done
Binary file modified README.pdf
Binary file not shown.
17 changes: 17 additions & 0 deletions app/assets/stylesheets/global.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ a.btn {
}
}

#flash_container {
position: fixed;

width: auto;
top: 10px;
left: 500px;
right: 20%;

.alert {
width: 100%;
border-radius: 20px;
box-shadow: 10px 10px 10px #222;
}
.alert-danger {
h3 { color: #f55 !important; }
}
}

nav.navbar {
width: 100%;
Expand Down
15 changes: 10 additions & 5 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def require_logged_in_user
end

def configure_permitted_parameters
attributes = %i[name first last email avatar]
devise_parameter_sanitizer.permit(:sign_up, keys: attributes)
devise_parameter_sanitizer.permit(:account_update, keys: attributes)
permitted_attributes = %i[email password password_confirmation first last]
devise_parameter_sanitizer.permit(:sign_up) { |user| user.permit(*permitted_attributes) }
devise_parameter_sanitizer.permit(:account_update) { |user| user.permit(*permitted_attributes) }
end

def authenticate_user_from_token!
Expand All @@ -44,7 +44,12 @@ def authenticate_user_from_token!
end
end

def render_flash
render turbo_stream: turbo_stream.update('flash', partial: 'shared/flash')
def render_flash(flash)
# render turbo_stream: turbo_stream.update('flash_container', partial: 'shared/flash')
respond_to do |format|
format.turbo_stream do
render turbo_stream: [turbo_stream.replace(:flash, partial: 'shared/flash', locals: { flash: })]
end
end
end
end
4 changes: 2 additions & 2 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def create
redirect_to @event
else
Rails.logger.error("Can't create event: #{@event.errors.full_messages}")
flash.now[:error] = "There was a problem creating the event: #{@event.errors.full_messages.join('. ')}"
render_flash
flash.now[:error] = "There was a problem creating the event: #{@event.errors.full_messages.sort.uniq.join('. ')}"
render_flash flash
end
end

Expand Down
11 changes: 11 additions & 0 deletions app/javascript/add_jquery.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import jquery from "jquery";

window.jQuery = jquery;
window.$ = jquery;

// https://dev.to/nejremeslnici/how-to-use-view-transitions-in-hotwire-turbo-1kdi
addEventListener("turbo:before-frame-render", (event) => {
if (document.startViewTransition) {
const originalRender = event.detail.render
event.detail.render = (currentElement, newElement) => {
document.startViewTransition(()=> originalRender(currentElement, newElement))
}
}
})
26 changes: 26 additions & 0 deletions app/javascript/controllers/flash_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {Controller} from "@hotwired/stimulus"

// Connects to data-controller="flash"
export default class flashController extends Controller {
static targets = [ "flash" ]

connect() {
addEventListener("turbo:render", (event) => {
this.hideFlash()
})
addEventListener("turbo:before-stream-render", (event) => {
this.hideFlash()
})
}

hideFlash() {
setTimeout(function () {
$('#flash_container').fadeOut('500');
setTimeout(function () {
$('#flash').html("");
$('#flash_container').show();
}, 500);

}, 5000);
}
}
3 changes: 3 additions & 0 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { application } from "./application"
import FlatpickrController from "./flatpickr_controller"
application.register("flatpickr", FlatpickrController)

import FlashController from "./flash_controller"
application.register("flash", FlashController)

import PaymentsController from "./payments_controller"
application.register("payments", PaymentsController)

Expand Down
44 changes: 22 additions & 22 deletions app/javascript/popovers.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import jQuery from 'jquery';

(function ($) {
const popover = $('.help-popover');
popover({
trigger: 'manual'
}).on('click', function (e) {
const popoverClicked = $(this);
popoverClicked('toggle');
e.preventDefault();
});
})(jQuery);

(function () {
jQuery(function () {
$("a[rel~=popover], .has-popover").popover;
return $("a[rel~=tooltip], .has-tooltip").tooltip;
});

}).call(this);

$('.hover-tooltip').tooltip();
// import jQuery from 'jquery';
//
// (function ($) {
// const popover = $('.help-popover');
// popover({
// trigger: 'manual'
// }).on('click', function (e) {
// const popoverClicked = $(this);
// popoverClicked('toggle');
// e.preventDefault();
// });
// })(jQuery);
//
// (function () {
// jQuery(function () {
// $("a[rel~=popover], .has-popover").popover;
// return $("a[rel~=tooltip], .has-tooltip").tooltip;
// });
//
// }).call(this);
//
// $('.hover-tooltip').tooltip();
31 changes: 22 additions & 9 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class Event < ApplicationRecord
:max_kid_tickets_per_request, :max_cabins_per_request, :max_cabin_requests,
:photo, :photo_cache, :tickets_require_approval, :require_mailing_address,
:allow_financial_assistance, :allow_donations,
:ticket_sales_start_time, :ticket_sales_end_time, :ticket_requests_end_time
:ticket_sales_start_time, :ticket_sales_end_time,
:ticket_requests_end_time

mount_uploader :photo, PhotoUploader

Expand All @@ -71,19 +72,31 @@ class Event < ApplicationRecord
validate :end_time_after_start_time, :sales_end_time_after_start_time,
:ensure_prices_set_if_maximum_specified

DEFAULT_ATTRIBUTES = {
DEFAULT_EVENT_START_TIME = ->(delta = 0) { Date.current + 2.months + delta }
DEFAULT_ATTRIBUTES = {
start_time: DEFAULT_EVENT_START_TIME[11.hours],
end_time: DEFAULT_EVENT_START_TIME[3.days + 14.hours],
ticket_requests_end_time: DEFAULT_EVENT_START_TIME[-14.days],
ticket_sales_start_time: DEFAULT_EVENT_START_TIME[-42.days],
ticket_sales_end_time: DEFAULT_EVENT_START_TIME[7.days],

adult_ticket_price: 250,
early_arrival_price: 20,
early_arrival_price: 0,
kid_ticket_price: 0,
late_departure_price: 20,
max_adult_tickets_per_request: 10,
late_departure_price: 25,

max_adult_tickets_per_request: 6,
max_kid_tickets_per_request: 4,
max_cabins_per_request: 1,
max_cabin_requests: 2,

tickets_require_approval: true,
require_mailing_address: false,
allow_financial_assistance: true,
allow_donations: true
allow_donations: true,

require_mailing_address: false,

max_cabins_per_request: nil,
max_cabin_requests: nil,
cabin_price: nil
}.freeze

def admin?(user)
Expand Down
4 changes: 2 additions & 2 deletions app/views/devise/registrations/_change_password.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- if existing
%small.nowrap NOTE: leave these fields blank if you don't want to change your password.
- else
%h3 Please enter your new password, twice for confirmation.
%h5 Please enter your new password, twice for confirmation.

.row
.col-md-6.col-sm-12
Expand All @@ -15,6 +15,6 @@
NOTE:
= "#{@minimum_password_length} characters minimum"

.col-6
.col-md-6.col-sm-12
%p= f.label :password_confirmation
%p= f.password_field :password_confirmation, autocomplete: "new-password"
9 changes: 1 addition & 8 deletions app/views/devise/registrations/_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

- http_method = existing ? :put : :post
= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: http_method }) do |f|
= form_for(resource, as: resource_name, url: user_registration_path, html: { method: http_method }) do |f|

= render "devise/shared/error_messages", resource: resource

Expand Down Expand Up @@ -43,13 +43,6 @@
.actions
= f.submit "Register", class: 'btn btn-primary btn-large'

.row
.col-12
.actions
%h3
Close my accounts completely.
%div
Wanna go? #{button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?", turbo_confirm: "Are you sure?" }, class: 'btn btn-secondary btn-large', method: :delete}

.row
.col-12
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/registrations/edit.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%h2
Edit Your Account

= render partial: 'form', locals: { existing: resource&.persisted?, resource: resource, resource_name: resource_name}
= render partial: 'form', locals: { existing: resource&.id.nil? ? false : true, resource: resource, resource_name: resource_name}
2 changes: 1 addition & 1 deletion app/views/devise/registrations/new.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
%h2 Register a New Account

= render partial: 'form', locals: { existing: resource&.persisted?, resource: resource, resource_name: resource_name}
= render partial: 'form', locals: { existing: resource&.id.nil? ? false : true, resource: resource, resource_name: resource_name}
6 changes: 3 additions & 3 deletions app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
!!!
%html{ lang: 'en', 'data-bs-theme': 'dark' }
%html{ lang: 'en', 'data-bs-theme': 'light' }
%head
%meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
%meta{:content => "width=device-width,initial-scale=1", :name => "viewport"}/
Expand Down Expand Up @@ -28,11 +28,11 @@
%body
= render partial: "shared/navigation"
.container
%turbo-frame#flash_container{"data-controller": "flash", "data-flash-target": "flash"}
= render "shared/flash"
.row
.col-3.col-md-3
.col-6.col-md-6
.turbo-frame#flash
= render 'shared/flash'
.col-3.col-md-3

.row
Expand Down
3 changes: 3 additions & 0 deletions app/views/layouts/application.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= turbo_stream.prepend :flash_container, partial: "shared/flash" %>

<%= yield %>
23 changes: 12 additions & 11 deletions app/views/shared/_flash.html.haml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
- flash.each do |type, msg|
.alert{ class: alert_class(type), role: "alert"}
- main, rest = msg.split(/:/)
%h3
= main
- if rest != main && rest.present?
%hr
- rest.gsub(/.*:/, '').gsub(/["\[\]]/, '').split(', ').each do |message|
%ul
%li
= message
#flash{"data-flash-target": "flash"}
- flash.each do |type, msg|
.alert{ class: alert_class(type), role: "alert"}
- main, rest = msg.split(/:/)
%h3
= main
- if rest != main && rest.present?
%hr
- rest.gsub(/.*:/, '').gsub(/["\[\]]/, '').split(', ').each do |message|
%ul
%li
= message
2 changes: 1 addition & 1 deletion app/views/shared/_navigation.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%nav.navbar.navbar-expand-lg.border-bottom.border-body.navbar-dark
%nav.navbar.navbar-expand-lg.border-bottom.border-body.navbar-dark.bg-primary-subtle
%a.navbar-brand{ href: root_path }
= image_tag "/icons/nav-bar-logo.png", size: "80x80"
%button.navbar-toggler{"aria-controls" => "navbarSupportedContent", "aria-expanded" => "false", "aria-label" => "Toggle navigation", "data-bs-target" => "#navbarSupportedContent", "data-bs-toggle" => "collapse", :type => "button"}
Expand Down
7 changes: 1 addition & 6 deletions bin/boot-up
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,4 @@ run "bin/rails db:migrate"
run "bin/rails db:seed"
run "bundle exec rake db:test:prepare"

h1 "Starting Rails Server..."
run.set-next show-output-on
run "sleep 5 && open http://0.0.0.0:3000/" 2>/dev/null 1>&2 &
run "make dev"


success "Your server should be ready to roll. Run ${txtgrn}make dev${clr} to start it."
kigster marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VCDth9rl7xBy5IepxdQ4sH5s9sCi39B8/Gwzw+z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