diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1bd7c4c7e..bfa4078aa 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -9,7 +9,7 @@ class UsersController < ApplicationController def index redirect_to users_organisation_path(current_user.organisation) unless current_user.support? - @pagy, @users = pagy(User.all.where(active: true).includes(:organisation)) + @pagy, @users = pagy(filtered_users) respond_to do |format| format.html @@ -77,6 +77,15 @@ class UsersController < ApplicationController private + def filtered_users + search_param = params["user-search-field"] + if search_param + User.where("name LIKE ?", "%#{search_param}%").where(active: true).includes(:organisation) + else + User.all.where(active: true).includes(:organisation) + end + end + def format_error_messages errors = @user.errors.to_hash @user.errors.clear diff --git a/app/frontend/styles/_search.scss b/app/frontend/styles/_search.scss new file mode 100644 index 000000000..5c91ef41c --- /dev/null +++ b/app/frontend/styles/_search.scss @@ -0,0 +1,24 @@ +.app-search { + @include govuk-responsive-margin(6, "bottom"); + display: flex; + align-items: end; + } + + .app-search__form-group { + flex: 1; + margin-bottom: 0; + } + + .app-search__input { + background-image: url("data:image/svg+xml,%3Csvg class='app-search__icon' width='20' height='20' viewBox='0 0 27 27' fill='none' xmlns='http://www.w3.org/2000/svg' aria-hidden='true' focusable='false'%3E%3Ccircle cx='12.0161' cy='11.0161' r='8.51613' stroke='currentColor' stroke-width='3'%3E%3C/circle%3E%3Cline x1='17.8668' y1='17.3587' x2='26.4475' y2='25.9393' stroke='currentColor' stroke-width='3'%3E%3C/line%3E%3C/svg%3E"); + background-repeat: no-repeat; + background-size: 1em 1em; + background-position: 7px center; + padding-left: govuk-spacing(6); + } + + .app-search__button { + margin-left: govuk-spacing(1); + margin-bottom: 2px; + width: auto; + } \ No newline at end of file diff --git a/app/frontend/styles/application.scss b/app/frontend/styles/application.scss index ebe0af05f..883ea5e63 100644 --- a/app/frontend/styles/application.scss +++ b/app/frontend/styles/application.scss @@ -39,6 +39,7 @@ $govuk-breakpoints: ( @import "pagination"; @import "panel"; @import "primary-navigation"; +@import "search"; // App utilities .app-\!-colour-muted { diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 87e5b37a0..74c671e39 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -7,6 +7,24 @@ <% if current_user.data_coordinator? || current_user.support? %> <%= govuk_button_link_to "Invite user", new_user_path, html: { method: :get } %> <% end %> + +<%= form_with model: @user, url: users_path(), method: "get", local: true do |f| %> +