Skip to content

Commit

Permalink
sorting Ok
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexGrouard committed Feb 14, 2023
1 parent 91aaa77 commit 642c89a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/containers/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export default class {
handleEditTicket(e, bill, bills) {
if (this.counter === undefined || this.id !== bill.id) this.counter = 0
if (this.id === undefined || this.id !== bill.id) this.id = bill.id
if (this.id === bill.id) this.counter = 0
if (this.counter % 2 === 0) {
bills.forEach(b => {
$(`#open-bill${b.id}`).css({ background: '#0D5AE5' })
Expand Down Expand Up @@ -146,7 +145,7 @@ export default class {
}

bills.forEach(bill => {
$(`#open-bill${bill.id}`).click((e) => this.handleEditTicket(e, bill, bills))
$(`#open-bill${bill.id}`).off().on("click",((e) => this.handleEditTicket(e, bill, bills)));
})

return bills
Expand Down
14 changes: 9 additions & 5 deletions src/containers/NewBill.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class NewBill {
this.fileName = null
this.billId = null
new Logout({ document, localStorage, onNavigate })
//disable submit button
}
handleChangeFile = e => {
e.preventDefault()
Expand All @@ -27,7 +28,12 @@ export default class NewBill {
formData.append('file', file)
formData.append('email', email)


if (fileExtension != "png" && fileExtension != "jpg" && fileExtension != "jpeg") {
//disable submit button
//add error message
}
else {
//enable submit button
this.store
.bills()
.create({
Expand All @@ -41,11 +47,9 @@ export default class NewBill {
this.billId = key
this.fileUrl = fileUrl
this.fileName = fileName
if (fileExtension != "png" && fileExtension != "jpg" && fileExtension != "jpeg") {
throw new Error ("Wrong file extension ")
}

}).catch(error => console.error(error))

}
}

handleSubmit = e => {
Expand Down
6 changes: 5 additions & 1 deletion src/views/BillsUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ const row = (bill) => {
}

const rows = (data) => {
return (data && data.length) ? data.map(bill => row(bill)).join("") : ""
if ((data && data.length)) {
const dataSorted = data.sort((a, b)=> ((a.date < b.date) ? 1 : -1))
return (dataSorted.map(bill => row(bill)).join(""))
}
else {return ("")}
}

export default ({ data: bills, loading, error }) => {
Expand Down

0 comments on commit 642c89a

Please sign in to comment.