use service to create offer
This commit is contained in:
parent
e046c8c118
commit
873493f697
3 changed files with 20 additions and 9 deletions
|
|
@ -10,13 +10,16 @@ const TrustCheckboxes = require('../components/TrustCheckboxes');
|
|||
const BigNotesCheckbox = require('../components/BigNotesCheckbox');
|
||||
const PopupNotification = require('../components/PopupNotification');
|
||||
|
||||
const offerService = require('../services/offerService');
|
||||
|
||||
class CreateOfferModal {
|
||||
// Actual creation logic to be provided by a service
|
||||
// Stop relying on IDs
|
||||
constructor({ parentElement, onCreationCallback }) {
|
||||
constructor({ parentElement, onCreationCallback, offerService }) {
|
||||
this.element = null;
|
||||
this.parentElement = parentElement;
|
||||
this.onCreationCallback = onCreationCallback;
|
||||
this.offerService = offerService;
|
||||
|
||||
this.publishOfferButton = null;
|
||||
this.buyOrSellButtonGroup = null;
|
||||
|
|
@ -230,13 +233,7 @@ class CreateOfferModal {
|
|||
are_big_notes_accepted,
|
||||
};
|
||||
|
||||
await fetch('/api/offer', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ offerDetails }),
|
||||
});
|
||||
await this.offerService.createOffer(offerDetails);
|
||||
|
||||
this.toggle();
|
||||
}
|
||||
|
|
@ -262,6 +259,7 @@ function offersPage() {
|
|||
await myOffers.render();
|
||||
offerCreatedPopup.displayTemporarily(3000);
|
||||
},
|
||||
offerService: offerService,
|
||||
});
|
||||
createOfferModal.render();
|
||||
// -----------
|
||||
|
|
|
|||
13
src/front/services/offerService.js
Normal file
13
src/front/services/offerService.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
const createOffer = async (offerDetails) => {
|
||||
await fetch('/api/offer', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ offerDetails }),
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
createOffer,
|
||||
};
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
<p>Vaya, no hay nada por aquí...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script src="/javascript/offers.bundle.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue