diff --git a/app/controllers/assignments_controller.rb b/app/controllers/assignments_controller.rb deleted file mode 100644 index 57060720..00000000 --- a/app/controllers/assignments_controller.rb +++ /dev/null @@ -1,71 +0,0 @@ -class AssignmentsController < ApplicationController - before_action :require_user! - before_action :set_assignment, only: %i[ show edit update destroy ] - - # GET /assignments or /assignments.json - def index - @assignments = Assignment.all - end - - # GET /assignments/1 or /assignments/1.json - def show - end - - # GET /assignments/new - def new - @assignment = Assignment.new - end - - # GET /assignments/1/edit - def edit - end - - # POST /assignments or /assignments.json - def create - @assignment = Assignment.new(assignment_params) - - respond_to do |format| - if @assignment.save - format.html { redirect_to assignment_url(@assignment), notice: "Assignment was successfully created." } - format.json { render :show, status: :created, location: @assignment } - else - format.html { render :new, status: :unprocessable_entity } - format.json { render json: @assignment.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /assignments/1 or /assignments/1.json - def update - respond_to do |format| - if @assignment.update(assignment_params) - format.html { redirect_to assignment_url(@assignment), notice: "Assignment was successfully updated." } - format.json { render :show, status: :ok, location: @assignment } - else - format.html { render :edit, status: :unprocessable_entity } - format.json { render json: @assignment.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /assignments/1 or /assignments/1.json - def destroy - @assignment.destroy! - - respond_to do |format| - format.html { redirect_to assignments_url, notice: "Assignment was successfully destroyed." } - format.json { head :no_content } - end - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_assignment - @assignment = Assignment.find(params[:id]) - end - - # Only allow a list of trusted parameters through. - def assignment_params - params.require(:assignment).permit(:user_id, :project_id, :status) - end -end diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb deleted file mode 100644 index 44fed292..00000000 --- a/app/controllers/clients_controller.rb +++ /dev/null @@ -1,55 +0,0 @@ -class ClientsController < ApplicationController - before_action :require_user! - before_action :set_client, only: %i[ show edit update toggle_archived ] - - def index - @clients = current_company.clients.all - end - - def show - end - - def new - @client = Client.new - end - - def edit - end - - def create - @client = current_company.clients.new(create_client_params) - - if @client.save - redirect_to client_url(@client), notice: "Client was successfully created." - else - render :new, status: :unprocessable_entity - end - end - - def update - if @client.update(update_client_params) - redirect_to client_url(@client), notice: "Client was successfully updated." - else - render :edit, status: :unprocessable_entity - end - end - - def toggle_archived - @client.toggle_archived! - - redirect_to clients_url, notice: "Client status was successfully updated." - end - - private - def set_client - @client = current_company.clients.find(params[:id]) - end - - def create_client_params - params.require(:client).permit(:name, :description) - end - - def update_client_params - params.require(:client).permit(:name, :description, :status, :avatar) - end -end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb deleted file mode 100644 index 86526afe..00000000 --- a/app/controllers/projects_controller.rb +++ /dev/null @@ -1,54 +0,0 @@ -class ProjectsController < ApplicationController - before_action :require_user! - before_action :set_project, only: %i[ show edit update ] - - def index - @projects = Project.includes(:company). all - end - - def show - end - - def new - @client = Client.find_by(id: params[:client_id]) # optional - @project = Project.new( - client_id: params[:client_id], - - # TODO: make these configurable? - status: Project::UNCONFIRMED, - payment_frequency: Project::MONTHLY - ) - end - - def edit - end - - def create - @project = Project.new(project_params) - - if @project.save - redirect_to project_url(@project), notice: "Project was successfully created." - else - render :new, status: :unprocessable_entity - end - end - - def update - if @project.update(project_params) - redirect_to project_url(@project), notice: "Project was successfully updated." - else - render :edit, status: :unprocessable_entity - end - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_project - @project = Project.find(params[:id]) - end - - # Only allow a list of trusted parameters through. - def project_params - params.require(:project).permit(:client_id, :name, :status, :cost, :payment_frequency) - end -end diff --git a/app/controllers/settings/users_controller.rb b/app/controllers/settings/users_controller.rb index 1c4a863e..9b851ce6 100644 --- a/app/controllers/settings/users_controller.rb +++ b/app/controllers/settings/users_controller.rb @@ -45,7 +45,11 @@ def create rescue ActiveRecord::RecordInvalid @user = @command.user @user.valid? - render :new + + respond_to do |format| + format.html { render :new } + format.turbo_stream + end end end diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index a0bb8666..81918f84 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -6,11 +6,24 @@ def show end def update - if current_company.update(update_params) - flash[:success] = "Company updated successfully" + # handle avatar changes first + if update_params[:avatar].present? + current_company.assign_attributes(avatar: update_params[:avatar]) + current_company.attachment_changes.any? && current_company.save + end + + current_company.assign_attributes(update_params.except(:avatar)) + + if current_company.save + flash[:success] = "Updates saved!" redirect_to settings_path else - render :show + flash.now[:error] = "Some information couldn't be saved." + + respond_to do |format| + format.turbo_stream + format.html { render :show } + end end end diff --git a/app/controllers/users/profile_controller.rb b/app/controllers/users/profile_controller.rb index 9b21bb15..6ab0a24f 100644 --- a/app/controllers/users/profile_controller.rb +++ b/app/controllers/users/profile_controller.rb @@ -4,11 +4,24 @@ def show end def update - if current_user.update(user_params) - flash[:notice] = 'Your profile was updated successfully' + # handle avatar changes first + if user_params[:avatar].present? + current_user.assign_attributes(avatar: user_params[:avatar]) + current_user.attachment_changes.any? && current_user.save + end + + current_user.assign_attributes(user_params.except(:avatar)) + + if current_user.save + flash[:success] = 'Your profile was updated successfully' redirect_to users_profile_path else - render :show + flash.now[:error] = 'There was a problem updating your profile' + + respond_to do |format| + format.turbo_stream + format.html { render :show } + end end end diff --git a/app/helpers/assignments_helper.rb b/app/helpers/assignments_helper.rb deleted file mode 100644 index 6f7c33b9..00000000 --- a/app/helpers/assignments_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module AssignmentsHelper -end diff --git a/app/helpers/clients_helper.rb b/app/helpers/clients_helper.rb deleted file mode 100644 index 90159068..00000000 --- a/app/helpers/clients_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ClientsHelper -end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb deleted file mode 100644 index db5c5ce1..00000000 --- a/app/helpers/projects_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ProjectsHelper -end diff --git a/app/models/company.rb b/app/models/company.rb index 4f6dce53..c2fb1530 100644 --- a/app/models/company.rb +++ b/app/models/company.rb @@ -39,4 +39,17 @@ def can_access?(user:) membership = memberships.find_by(user: user) membership.present? && membership.active? end + + def restore_avatar + if avatar.attached? && avatar.changed? + original_picture = avatar.attachment_was + if original_picture + # Detach the current attachment + avatar.detach + + # Reattach the original attachment + avatar.attach(original_picture) + end + end + end end diff --git a/app/views/assignments/_assignment.html.erb b/app/views/assignments/_assignment.html.erb deleted file mode 100644 index 55b7ec96..00000000 --- a/app/views/assignments/_assignment.html.erb +++ /dev/null @@ -1,22 +0,0 @@ -
-

- User: - <%= assignment.user_id %> -

- -

- Project: - <%= assignment.project_id %> -

- -

- Status: - <%= assignment.status %> -

- - <% if action_name != "show" %> - <%= link_to "Show this assignment", assignment, class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> - <%= link_to "Edit this assignment", edit_assignment_path(assignment), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %> -
- <% end %> -
diff --git a/app/views/assignments/_assignment.json.jbuilder b/app/views/assignments/_assignment.json.jbuilder deleted file mode 100644 index 8ee3e273..00000000 --- a/app/views/assignments/_assignment.json.jbuilder +++ /dev/null @@ -1,2 +0,0 @@ -json.extract! assignment, :id, :user_id, :project_id, :proposed, :status, :created_at, :updated_at -json.url assignment_url(assignment, format: :json) diff --git a/app/views/assignments/_form.html.erb b/app/views/assignments/_form.html.erb deleted file mode 100644 index d43ea039..00000000 --- a/app/views/assignments/_form.html.erb +++ /dev/null @@ -1,32 +0,0 @@ -<%= form_with(model: assignment, class: "contents") do |form| %> - <% if assignment.errors.any? %> -
-

<%= pluralize(assignment.errors.count, "error") %> prohibited this assignment from being saved:

- - -
- <% end %> - -
- <%= form.label :user_id %> - <%= form.select :user_id, current_company.users.map { |u| [u.name, u.id] }, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> -
- -
- <%= form.label :project_id %> - <%= form.select :project_id, current_company.projects.map { |p| [p.name, p.id] }, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> -
- -
- <%= form.label :status %> - <%= form.select :status, Assignment::VALID_STATUSES, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> -
- -
- <%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> -
-<% end %> diff --git a/app/views/assignments/edit.html.erb b/app/views/assignments/edit.html.erb deleted file mode 100644 index 0cbdf8e0..00000000 --- a/app/views/assignments/edit.html.erb +++ /dev/null @@ -1,8 +0,0 @@ -
-

Editing assignment

- - <%= render "form", assignment: @assignment %> - - <%= link_to "Show this assignment", @assignment, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> - <%= link_to "Back to assignments", assignments_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -
diff --git a/app/views/assignments/index.html.erb b/app/views/assignments/index.html.erb deleted file mode 100644 index d14eae99..00000000 --- a/app/views/assignments/index.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -
- <% if notice.present? %> -

<%= notice %>

- <% end %> - -
-

Assignments

- <%= link_to "New assignment", new_assignment_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %> -
- -
- <%= render @assignments %> -
-
diff --git a/app/views/assignments/index.json.jbuilder b/app/views/assignments/index.json.jbuilder deleted file mode 100644 index 32843e10..00000000 --- a/app/views/assignments/index.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.array! @assignments, partial: "assignments/assignment", as: :assignment diff --git a/app/views/assignments/new.html.erb b/app/views/assignments/new.html.erb deleted file mode 100644 index 542c0e74..00000000 --- a/app/views/assignments/new.html.erb +++ /dev/null @@ -1,7 +0,0 @@ -
-

New assignment

- - <%= render "form", assignment: @assignment %> - - <%= link_to "Back to assignments", assignments_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -
diff --git a/app/views/assignments/show.html.erb b/app/views/assignments/show.html.erb deleted file mode 100644 index c3be5c03..00000000 --- a/app/views/assignments/show.html.erb +++ /dev/null @@ -1,15 +0,0 @@ -
-
- <% if notice.present? %> -

<%= notice %>

- <% end %> - - <%= render @assignment %> - - <%= link_to "Edit this assignment", edit_assignment_path(@assignment), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -
- <%= button_to "Destroy this assignment", assignment_path(@assignment), method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %> -
- <%= link_to "Back to assignments", assignments_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -
-
diff --git a/app/views/assignments/show.json.jbuilder b/app/views/assignments/show.json.jbuilder deleted file mode 100644 index d8c00782..00000000 --- a/app/views/assignments/show.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.partial! "assignments/assignment", assignment: @assignment diff --git a/app/views/clients/edit.html.erb b/app/views/clients/edit.html.erb deleted file mode 100644 index 03ec9657..00000000 --- a/app/views/clients/edit.html.erb +++ /dev/null @@ -1,68 +0,0 @@ -
- <%= render(Settings::BreadcrumbsComponent.new) do |breadcrumbs_component| - breadcrumbs_component.with_breadcrumb(title: "Clients", link: clients_path, first: true) do |clients_icon| - clients_icon.with_svg do %> - - - - <% end - end - breadcrumbs_component.with_breadcrumb(title: @client.name, last: true) - end %> -
- -
- <%= form_for @client, url: client_path(@client) do |f| %> -
-
-

Add a new client

- - <% if @client.errors.any? %> -
-
-
- -
-
-

There were <%= pluralize(@client.errors.count, "error") %> with adding the user to your company

-
-
    - <% @client.errors.full_messages.each do |error| %> -
  • <%= error %>
  • - <% end %> -
-
-
-
-
- <% end %> - -
-
- <%= f.label :name, "Client name", class: "block text-sm font-medium leading-6 text-gray-900" %> -
- <%= f.text_field :name, class: "block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" %> -
-
- -
- <%= f.label :email, "Description", class: "block text-sm font-medium leading-6 text-gray-900" %> -
- <%= f.text_area :description, class: "block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" %> -
-
- - <%= render(Shared::ManageAvatarComponent.new(attachable: @client, form: f)) %> -
-
-
- -
- <%= link_to "Cancel", client_path(@client), class: "text-sm font-semibold leading-6 text-gray-900" %> - <%= submit_tag "Save changes", data: {disable_with: "Please wait..."}, class: "rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" %> -
- <% end %> - -
\ No newline at end of file diff --git a/app/views/clients/index.html.erb b/app/views/clients/index.html.erb deleted file mode 100644 index 0c8eca72..00000000 --- a/app/views/clients/index.html.erb +++ /dev/null @@ -1,15 +0,0 @@ -
-

Clients

-
- <%= link_to "New Client", new_client_path, class: "ml-3 inline-flex items-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" %> -
-
- - -
- -
\ No newline at end of file diff --git a/app/views/clients/new.html.erb b/app/views/clients/new.html.erb deleted file mode 100644 index 4939f537..00000000 --- a/app/views/clients/new.html.erb +++ /dev/null @@ -1,62 +0,0 @@ -
- <%= link_to clients_path, class: "ml-3 inline-flex items-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" do %> - - - - Back - <% end %> -
- -
- <%= form_for @client, url: clients_path, data: {turbo: false} do |f| %> -
-
-

Add a new client

- - <% if @client.errors.any? %> -
-
-
- -
-
-

There were <%= pluralize(@client.errors.count, "error") %> with adding the user to your company

-
-
    - <% @client.errors.full_messages.each do |error| %> -
  • <%= error %>
  • - <% end %> -
-
-
-
-
- <% end %> - -
-
- <%= f.label :name, "Client name", class: "block text-sm font-medium leading-6 text-gray-900" %> -
- <%= f.text_field :name, class: "block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" %> -
-
- -
- <%= f.label :email, "Description", class: "block text-sm font-medium leading-6 text-gray-900" %> -
- <%= f.text_area :description, class: "block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" %> -
-
-
-
-
- -
- <%= link_to "Cancel", clients_path, class: "text-sm font-semibold leading-6 text-gray-900" %> - <%= submit_tag "Create", data: {disable_with: "Please wait..."}, class: "rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" %> -
- <% end %> - -
\ No newline at end of file diff --git a/app/views/clients/show.html.erb b/app/views/clients/show.html.erb deleted file mode 100644 index ae8aa5a6..00000000 --- a/app/views/clients/show.html.erb +++ /dev/null @@ -1,112 +0,0 @@ -
- <%= render(Settings::BreadcrumbsComponent.new) do |breadcrumbs_component| - breadcrumbs_component.with_breadcrumb(title: "Clients", link: clients_path, first: true) do |clients_icon| - clients_icon.with_svg do %> - - - - <% end - end - breadcrumbs_component.with_breadcrumb(title: @client.name, last: true) - end %> - -
- <%= link_to "Edit", edit_client_path(@client), class: "ml-3 inline-flex items-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" %> - - <% link_text = @client.active? ? 'Archive' : 'Activate' %> - <% confirmation_text = @client.active? ? 'Are you sure? This will archive all projects for this client.' : "Are you sure?" %> - <%= button_to link_text, toggle_archived_client_path(@client), method: :post, data: { turbo_confirm: confirmation_text }, form_class: "inline", class: "ml-3 inline-flex items-center rounded-md bg-red-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-red-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-red-600" %> -
-
- -
-
-
-
Client name
-
- <%= @client.name %> -
-
-
-
Description
-
- <%= @client.description.presence || "N/A" %> -
-
-
-
Avatar
-
- <%= image_tag AvatarHelper.new(target: @client).image_url, class: "h-24 w-24 rounded-full" %> -
-
-
-
Projects
-
-
    -
  • -
    - <%= link_to new_project_path(client_id: @client.id), class: "inline-flex items-center gap-x-1.5 rounded-md bg-indigo-600 px-2.5 py-1.5 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" do %> - - - - - New Project - <% end %> -
    -
  • - <% @client.projects.each do |project| %> -
  • -
    - <% if project.confirmed? %> - - - Active - - - <% elsif project.unconfirmed? %> - - - Unconfirmed - - <% elsif project.archived? %> - - - Archived - - <% elsif project.cancelled? %> - - - Cancelled - - <% elsif project.completed? %> - - - Completed - - <% end %> -
    - - <%= link_to project.name, project_path(project) %> - -
    -
    -
    - <%= link_to "View StaffPlan", "#", class: "font-medium text-indigo-600 hover:text-indigo-500", onclick: "alert('this will take you to the React front end')" %> -
    -
  • - <% end %> -
-
-
-
-
\ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index b6eb0192..f18a0f69 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -14,14 +14,9 @@