-
Notifications
You must be signed in to change notification settings - Fork 88
Add delete and bulk delete functionality for invoices #386
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class InternalApi::V1::Invoices::BulkDeletionController < InternalApi::V1::ApplicationController | ||
| def create | ||
| authorize :create, policy_class: Invoices::BulkDeletionPolicy | ||
| invoices = Invoice.where(id: params[:invoices_ids]) | ||
| invoices.destroy_all | ||
| head :no_content | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,8 @@ const Header = ({ | |
| setFilterVisibilty, | ||
| isInvoiceSelected, | ||
| selectedInvoiceCount, | ||
| clearCheckboxes | ||
| clearCheckboxes, | ||
| setShowBulkDeleteDialog | ||
| }) => ( | ||
| <div className="mt-6 mb-3 sm:flex sm:items-center sm:justify-between"> | ||
| <h2 className="header__title">Invoices</h2> | ||
|
|
@@ -65,6 +66,9 @@ const Header = ({ | |
| <div className="flex"> | ||
| <button | ||
| type="button" | ||
| onClick={()=> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if the status of the selected invoices is
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, only draft and declined invoices can be deleted. |
||
| setShowBulkDeleteDialog(true); | ||
| }} | ||
| className="header__button border-miru-red-400 text-miru-red-400" | ||
| > | ||
| <Trash weight="fill" size={16} /> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import React from "react"; | ||
| import invoicesApi from "apis/invoices"; | ||
|
|
||
| interface IProps { | ||
| invoices_ids: any; | ||
| setShowBulkDeleteDialog : any; | ||
| fetchInvoices: any | ||
| } | ||
|
|
||
| const BulkDeleteInvoices = ({ invoices_ids, setShowBulkDeleteDialog, fetchInvoices }: IProps) => { | ||
| const destroyInvoices = async invoices_ids => { | ||
| try { | ||
| await invoicesApi.destroyBulk({ invoices_ids }); | ||
| setShowBulkDeleteDialog(false); | ||
| fetchInvoices(); | ||
| } catch (error) { | ||
| console.error(error); | ||
| } | ||
| }; | ||
| return ( | ||
| <div className="px-4 flex items-center justify-center"> | ||
| <div | ||
| className="overflow-auto fixed top-0 left-0 right-0 bottom-0 inset-0 z-10 flex items-start justify-center" | ||
| style={{ | ||
| backgroundColor: "rgba(29, 26, 49, 0.6)" | ||
| }} | ||
| > | ||
| <div className="relative px-4 h-full w-full md:flex md:items-center md:justify-center"> | ||
| <div className="rounded-lg px-6 pb-6 bg-white shadow-xl transform transition-all sm:align-middle sm:max-w-md modal-width"> | ||
| <div className="flex-col my-8"> | ||
| <h6 className="text-2xl font-bold mb-2">Delete Invoices</h6> | ||
| <p className="font-normal mt-2"> | ||
| Are you sure you want to delete these invoice? | ||
| <b className="font-bold"></b> This action cannot | ||
| be reversed. | ||
| </p> | ||
| </div> | ||
| <div className="flex justify-between"> | ||
| <button | ||
| className="button__bg_transparent" | ||
| onClick={() => { | ||
| setShowBulkDeleteDialog (false); | ||
| }} | ||
| > | ||
| CANCEL | ||
| </button> | ||
| <button | ||
| className="button__bg_purple" | ||
| onClick={() => { | ||
| destroyInvoices(invoices_ids); | ||
| }} | ||
| > | ||
| DELETE | ||
| </button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
| export default BulkDeleteInvoices; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import React from "react"; | ||
| import invoicesApi from "apis/invoices"; | ||
|
|
||
| interface IProps { | ||
| invoice: any; | ||
| setShowDeleteDialog: any; | ||
| fetchInvoices: any; | ||
| } | ||
|
|
||
| const DeleteInvoice = ({ invoice, setShowDeleteDialog, fetchInvoices }: IProps) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BulkDeleteInvoices and DeleteInvoice can be combined in a single modal.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, It's good to have a single modal. Will create a separate PR for it. |
||
| const destroyInvoice = async invoice => { | ||
| try { | ||
| await invoicesApi.destroy(invoice); | ||
| setShowDeleteDialog(false); | ||
| fetchInvoices(); | ||
| } catch (error) { | ||
| console.error(error); | ||
| } | ||
| }; | ||
| return ( | ||
| <div className="px-4 flex items-center justify-center"> | ||
| <div | ||
| className="overflow-auto fixed top-0 left-0 right-0 bottom-0 inset-0 z-10 flex items-start justify-center" | ||
| style={{ | ||
| backgroundColor: "rgba(29, 26, 49, 0.6)" | ||
| }} | ||
| > | ||
| <div className="relative px-4 h-full w-full md:flex md:items-center md:justify-center"> | ||
| <div className="rounded-lg px-6 pb-6 bg-white shadow-xl transform transition-all sm:align-middle sm:max-w-md modal-width"> | ||
| <div className="flex-col my-8"> | ||
| <h6 className="text-2xl font-bold mb-2">Delete Invoice</h6> | ||
| <p className="font-normal mt-2"> | ||
| Are you sure you want to delete this invoice? | ||
| <b className="font-bold"></b> This action cannot | ||
| be reversed. | ||
| </p> | ||
| </div> | ||
| <div className="flex justify-between"> | ||
| <button | ||
| className="button__bg_transparent" | ||
| onClick={() => { | ||
| setShowDeleteDialog(false); | ||
| }} | ||
| > | ||
| CANCEL | ||
| </button> | ||
| <button | ||
| className="button__bg_purple" | ||
| onClick={() => { | ||
| destroyInvoice(invoice); | ||
| }} | ||
| > | ||
| DELETE | ||
| </button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
| export default DeleteInvoice; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the action name be
destroy?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@apoorv1316 We can add a
destroy_multipleaction ininvoices_controllerinstead of creating a separate controller just for this.cc: @rohitjoshixyz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mohd-anas-ansari that action won't be RESTful
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rohitjoshixyz Destroy action is a member route and we want to use a collection route for bulk_delete that's why we are using create action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use collection route for delete as well by explicitly mentioning it in routes.rb