Skip to content

Commit 9f01782

Browse files
committed
newSelectedPricingUnit
1 parent 72f8db9 commit 9f01782

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

services/static-webserver/client/source/class/osparc/store/Study.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,19 @@ qx.Class.define("osparc.store.Study", {
236236
},
237237

238238
updateSelectedPricingUnit: function(studyId, nodeId, planId, selectedPricingUnit) {
239+
let pricingUnit = null;
240+
if (selectedPricingUnit instanceof osparc.data.model.PricingUnit) {
241+
// convert to JSON if it's a model instance
242+
pricingUnit = JSON.parse(qx.util.Serializer.toJson(selectedPricingUnit));
243+
} else {
244+
pricingUnit = osparc.utils.Utils.deepCloneObject(selectedPricingUnit);
245+
}
239246
const params = {
240247
url: {
241248
studyId,
242249
nodeId,
243250
pricingPlanId: planId,
244-
pricingUnitId: selectedPricingUnit.getPricingUnitId(), // this should be just data
245-
// pricingUnitId: selectedPricingUnit["pricingUnitId"],
251+
pricingUnitId: pricingUnit["pricingUnitId"],
246252
}
247253
};
248254
return osparc.data.Resources.fetch("studies", "putPricingUnit", params)
@@ -251,7 +257,7 @@ qx.Class.define("osparc.store.Study", {
251257
if (!(studyId in this.__nodePricingUnit)) {
252258
this.__nodePricingUnit[studyId] = {};
253259
}
254-
this.__nodePricingUnit[studyId][nodeId] = selectedPricingUnit;
260+
this.__nodePricingUnit[studyId][nodeId] = pricingUnit;
255261
})
256262
.catch(err => {
257263
console.error("Failed to update selected pricing unit:", err);

services/static-webserver/client/source/class/osparc/study/NodePricingUnits.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ qx.Class.define("osparc.study.NodePricingUnits", {
105105
this._add(pricingUnitTiers);
106106
}
107107
pricingUnitTiers.addListener("selectPricingUnitRequested", e => {
108-
const selectedPricingUnitId = e.getData();
108+
const newSelectedPricingUnit = e.getData();
109109
if (this.isPatchNode()) {
110110
pricingUnitTiers.setEnabled(false);
111111
const pricingPlanId = this.getPricingPlanId();
112-
osparc.store.Study.updateSelectedPricingUnit(studyId, nodeId, pricingPlanId, selectedPricingUnitId)
113-
.then(() => pricingUnitTiers.setSelectedUnitId(selectedPricingUnitId))
112+
osparc.store.Study.updateSelectedPricingUnit(studyId, nodeId, pricingPlanId, newSelectedPricingUnit)
113+
.then(() => pricingUnitTiers.setSelectedUnitId(newSelectedPricingUnit.getPricingUnitId()))
114114
.catch(err => osparc.FlashMessenger.logError(err, this.tr("Cannot change Tier")))
115115
.finally(() => pricingUnitTiers.setEnabled(true));
116116
}

services/static-webserver/client/source/class/osparc/study/PricingUnitTiers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ qx.Class.define("osparc.study.PricingUnitTiers", {
7474
pricingUnitTiers.forEach(pricingUnitTier => {
7575
pricingUnitTier.addListener("selectPricingUnit", () => {
7676
if (changeSelectionAllowed) {
77-
this.fireDataEvent("selectPricingUnitRequested", pricingUnitTier.getUnitData().getPricingUnitId());
77+
this.fireDataEvent("selectPricingUnitRequested", pricingUnitTier.getUnitData());
7878
}
7979
});
8080
});

0 commit comments

Comments
 (0)