Skip to content

Commit cf62b4a

Browse files
committed
Merge branch 'feature/deleteDeclinePrice'
2 parents e2e176d + b0ff395 commit cf62b4a

12 files changed

Lines changed: 250 additions & 75 deletions

File tree

client/src/components/Inventory/Linnworks/Item/ItemTabs/Overview/FieldTemplates/Prices/GtcPrices.vue

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,26 @@
1414
:rules="rules.retailPrice"
1515
/>
1616

17-
<ItemTextFieldPrice
18-
v-if="declinePrice"
19-
class="ml-2 d-flex"
20-
:itemValue.sync="declinePrice"
21-
:itemId="item.pkStockItemID"
22-
:locationId="item.LocationId"
23-
:unlocked="unlocked"
24-
fieldName="DeclinePrice"
25-
fieldId="DeclinePrice"
26-
fieldLabel="Decline Price"
27-
fieldHint="Decline Price"
28-
@hasChanges="hasChanges"
29-
:rules="rules.declinePrice"
30-
/>
17+
<div class="d-flex">
18+
<div class="d-flex">
19+
<ItemTextFieldPrice
20+
v-if="declinePrice"
21+
class="ml-2 d-flex"
22+
:itemValue.sync="declinePrice"
23+
:itemId="item.pkStockItemID"
24+
:locationId="item.LocationId"
25+
:unlocked="unlocked"
26+
fieldName="DeclinePrice"
27+
fieldId="DeclinePrice"
28+
fieldLabel="Decline Price"
29+
fieldHint="Decline Price"
30+
@hasChanges="hasChanges"
31+
:rules="rules.declinePrice"
32+
:includeDeleteButton="true"
33+
:itemPriceId="declinePriceId"
34+
/>
35+
</div>
36+
</div>
3137

3238
<ItemTextFieldPriceAddNew
3339
v-if="!declinePrice"
@@ -63,6 +69,26 @@ export default {
6369
newPrice: false
6470
}),
6571
computed: {
72+
declinePriceId: {
73+
get: function() {
74+
if (this.item.prices && this.item.prices.length) {
75+
const declinePrice = this.item.prices.filter(price => price.Tag.toUpperCase() == "DECLINE");
76+
if (declinePrice && declinePrice.length > 0) {
77+
return declinePrice[0].pkRowId || false;
78+
}
79+
}
80+
return false;
81+
},
82+
set: function(value) {
83+
if (this.item.prices && this.item.prices.length) {
84+
this.item.prices = this.item.prices.reduce((acc, price) => {
85+
if (price.Tag.toUpperCase() == "DECLINE") price.pkRowId = value;
86+
acc.push(price);
87+
return acc;
88+
}, []);
89+
}
90+
}
91+
},
6692
declinePrice: {
6793
get: function() {
6894
if (this.item.prices && this.item.prices.length) {

client/src/components/Inventory/Linnworks/Item/ItemTabs/Overview/FieldTemplates/Prices/ItemTextFieldPrice.vue

Lines changed: 96 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
<v-slide-x-reverse-transition mode="out-in">
33
<div class="d-flex align-center justify-space-between" :key="`${fieldName}_${unlocked}_${itemId}`">
44
<slot v-if="!unlocked">
5-
<div class="d-flex align-baseline justify-start">
6-
<h4 class="my-0 mr-2">
7-
{{ fieldLabel }}
8-
</h4>
5+
<div class="d-flex align-baseline justify-end">
6+
<h4 class="my-0 mr-2">{{ fieldLabel }}</h4>
97
<h3 class="white--text textShadow my-0">
108
<div v-if="itemValue">
119
{{ itemValue | currency }}
@@ -19,58 +17,76 @@
1917

2018
<slot name="editField" v-if="unlocked" class="w-100">
2119
<div id="editFieldSlot" class="w-100">
22-
<EditDialog
23-
v-if="itemValue"
24-
dialogColor="grey darken-3"
25-
persistent
26-
large
27-
@save="saveChanges(itemId, fieldName, editValue, editValue, locationId)"
28-
@cancel="editValue = itemValue"
29-
>
30-
<div class="d-flex align-center justify-end w-100" id="editFieldWrapper">
31-
<h4 class="my-0 mr-2">
32-
{{ fieldLabel }}
33-
</h4>
20+
<div class="d-flex" v-if="itemValue">
21+
<EditDialog
22+
v-if="itemValue"
23+
dialogColor="grey darken-3"
24+
persistent
25+
large
26+
@save="saveChanges(itemId, fieldName, editValue, editValue, locationId)"
27+
@cancel="editValue = itemValue"
28+
>
29+
<div class="d-flex align-center justify-end w-100" id="editFieldWrapper">
30+
<h4 class="my-0 mr-2">{{ fieldLabel }}</h4>
3431

35-
<v-text-field
36-
dense
37-
hide-details
38-
:value="itemValue"
39-
:id="fieldId"
40-
:name="fieldName"
41-
:label="fieldLabel"
42-
:hint="fieldHint"
43-
filled
44-
:full-width="true"
45-
disabled
46-
background-color="grey darken-3"
47-
>
48-
<template v-slot:append-outer>
49-
<v-btn color="primary">
50-
<v-icon small>fa fa-edit</v-icon>
51-
</v-btn>
52-
</template>
53-
</v-text-field>
54-
</div>
55-
56-
<template v-slot:input>
57-
<div class="itemTextFieldInputSlot">
58-
<h3 class="my-1 textShadow">Edit {{ fieldLabel }}</h3>
5932
<v-text-field
60-
autocomplete="off"
61-
autofocus
62-
:full-width="true"
63-
filled
64-
background-color="grey darken-4"
65-
counter
33+
dense
34+
hide-details
35+
:value="itemValue"
36+
:id="fieldId"
37+
:name="fieldName"
6638
:label="fieldLabel"
67-
v-model="editValue"
68-
:rules="rules"
69-
@update:error="handleError"
70-
/>
39+
:hint="fieldHint"
40+
filled
41+
:full-width="true"
42+
disabled
43+
background-color="grey darken-3"
44+
>
45+
<template v-slot:append-outer>
46+
<v-btn color="primary">
47+
<v-icon small>fa fa-edit</v-icon>
48+
</v-btn>
49+
</template>
50+
</v-text-field>
7151
</div>
72-
</template>
73-
</EditDialog>
52+
53+
<template v-slot:input>
54+
<div class="itemTextFieldInputSlot">
55+
<div class="d-flex-column w-100 align-start justify-start">
56+
<div class="d-flex flex-grow-1">
57+
<h3 class="my-1 textShadow">Edit {{ fieldLabel }}</h3>
58+
</div>
59+
<div class="d-flex">
60+
<v-text-field
61+
autocomplete="off"
62+
autofocus
63+
:full-width="true"
64+
filled
65+
background-color="grey darken-4"
66+
counter
67+
:label="fieldLabel"
68+
v-model="editValue"
69+
:rules="rules"
70+
@update:error="handleError"
71+
/>
72+
</div>
73+
</div>
74+
</div>
75+
</template>
76+
</EditDialog>
77+
78+
<div class="d-flex justify-center align-center">
79+
<v-btn
80+
class="textShadow ml-5"
81+
color="error"
82+
v-if="includeDeleteButton"
83+
@click="deletePrice(itemPriceId)"
84+
style="min-width:20px;"
85+
>
86+
<v-icon small class="">fa fa-times-circle</v-icon>
87+
</v-btn>
88+
</div>
89+
</div>
7490

7591
<div v-else class="">
7692
<h3 class="white--text textShadow my-0">
@@ -84,7 +100,7 @@
84100
</template>
85101

86102
<script>
87-
import { UPDATE_PRICE_SELECTED_LINNWORKS_ITEM } from "@/store/action-types.js";
103+
import { UPDATE_PRICE_SELECTED_LINNWORKS_ITEM, DELETE_DECLINE_PRICE_SELECTED_LINNWORKS_ITEM } from "@/store/action-types.js";
88104
import EditDialog from "../EditDialog";
89105
90106
export default {
@@ -97,7 +113,9 @@ export default {
97113
fieldId: { type: [String] },
98114
fieldLabel: { type: [String] },
99115
fieldHint: { type: [String] },
100-
rules: { type: [Array] }
116+
rules: { type: [Array] },
117+
includeDeleteButton: { type: [Boolean], default: false },
118+
itemPriceId: { type: [String, Boolean], default: false }
101119
},
102120
components: {
103121
EditDialog
@@ -139,6 +157,30 @@ export default {
139157
}
140158
if (!result && error) this.$toastr.e(`${field} not updated!`, error);
141159
}
160+
},
161+
async deletePrice(inventoryItemPriceId) {
162+
const confirm = await this.$confirm(
163+
`<h3 class="text-center py-3">Delete this ${this.fieldLabel}?</h3>
164+
<p>This will remove the ${this.fieldLabel}. You cannot undo this operation. Are you sure you want to delete it?</p>`,
165+
{ title: `Delete this ${this.fieldLabel}?` }
166+
);
167+
if (confirm) this.callDeletePrice(inventoryItemPriceId);
168+
},
169+
async callDeletePrice(inventoryItemPriceId) {
170+
const pkStockItemID = this.itemId;
171+
const resp = await this.$store.dispatch(
172+
`linnworks/inventory/selectedItem/${DELETE_DECLINE_PRICE_SELECTED_LINNWORKS_ITEM}`,
173+
{ inventoryItemPriceId, pkStockItemID }
174+
);
175+
176+
const { result, error } = resp;
177+
if (result) {
178+
this.$toastr.defaultTimeout = 1500;
179+
this.$toastr.s(`${this.fieldLabel} update success!`, result);
180+
this.$emit("update:itemValue", "0.00");
181+
this.$emit("hasChanges", true);
182+
}
183+
if (!result && error) this.$toastr.e(`${this.fieldLabel} not updated!`, error);
142184
}
143185
}
144186
};

client/src/components/Inventory/Linnworks/Item/ItemTabs/Overview/OverviewTab.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@
123123
</v-col>
124124

125125
<v-col sm="12">
126-
<!-- UNLOCK WHEN PRICES CHANGES WORK
126+
<!-- UNLOCK WHEN PRICES CHANGES WORK -->
127127
<PricesContainer :item="item" :unlocked="unlocked" @hasChanges="hasChanges" />
128-
-->
129-
<PricesContainer :item="item" :unlocked="false" @hasChanges="hasChanges" />
128+
129+
<!-- <PricesContainer :item="item" :unlocked="false" @hasChanges="hasChanges" /> -->
130130
</v-col>
131131
</v-row>
132132
</v-col>

client/src/store/action-types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const UPDATE_EXTENDED_PROPERTY_SELECTED_LINNWORKS_ITEM = "UPDATE_EXTENDED
3636
export const UPDATE_TEMPLATE_INSTANT_SELECTED_LINNWORKS_ITEM = "UPDATE_TEMPLATE_INSTANT_SELECTED_LINNWORKS_ITEM";
3737
export const UPDATE_PRICE_SELECTED_LINNWORKS_ITEM = "UPDATE_PRICE_SELECTED_LINNWORKS_ITEM";
3838
export const ADD_PRICE_SELECTED_LINNWORKS_ITEM = "ADD_PRICE_SELECTED_LINNWORKS_ITEM";
39+
export const DELETE_DECLINE_PRICE_SELECTED_LINNWORKS_ITEM = "DELETE_DECLINE_PRICE_SELECTED_LINNWORKS_ITEM";
3940

4041
/* Ebay API */
4142
export const SEARCH_EBAY_ACTIVE = "SEARCH_EBAY_ACTIVE";

client/src/store/linnworks/inventory/selectedItem.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
UPDATE_PRICE_SELECTED_LINNWORKS_ITEM,
99
UPDATE_EXTENDED_PROPERTY_SELECTED_LINNWORKS_ITEM,
1010
UPDATE_TEMPLATE_INSTANT_SELECTED_LINNWORKS_ITEM,
11-
ADD_PRICE_SELECTED_LINNWORKS_ITEM
11+
ADD_PRICE_SELECTED_LINNWORKS_ITEM,
12+
DELETE_DECLINE_PRICE_SELECTED_LINNWORKS_ITEM
1213
} from "@/store/action-types";
1314

1415
import { SELECTED_LINNWORKS_ITEM_LOADING, SELECTED_LINNWORKS_ITEM_RESULT } from "@/store/mutation-types";
@@ -117,6 +118,19 @@ const selectedItem = {
117118
},
118119
{ root: true }
119120
);
121+
},
122+
async [DELETE_DECLINE_PRICE_SELECTED_LINNWORKS_ITEM]({ commit, dispatch }, payload) {
123+
return await dispatch(
124+
"api/requestHandler",
125+
{
126+
method: "post",
127+
url: `/inventory/deleteDeclinePrice`,
128+
params: payload,
129+
//success: `linnworks/inventory/selectedItem/${SELECTED_LINNWORKS_ITEM_RESULT}`,
130+
loading: `linnworks/inventory/selectedItem/${SELECTED_LINNWORKS_ITEM_LOADING}`
131+
},
132+
{ root: true }
133+
);
120134
}
121135
}
122136
};

server/handlers/v1/inventory/linnworks/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = (fastify) => {
2121
const { updatePriceHandler } = require("./inventoryItemUpdatePriceHandler")(fastify);
2222
const { addPriceHandler } = require("./inventoryItemAddPriceHandler")(fastify);
2323
const { selectToCloneHandler } = require("./inventoryItemSelectToCloneHandler")(fastify);
24+
const { deleteDeclinePriceHandler } = require("./inventoryItemDeleteDeclinePriceHandler")(fastify);
2425

2526
return {
2627
//START V2 improved search handler and code design
@@ -32,6 +33,7 @@ module.exports = (fastify) => {
3233
inventoryItemUpdatePriceHandler: updatePriceHandler,
3334
inventoryItemAddPriceHandler: addPriceHandler,
3435
inventoryItemSelectToCloneHandler: selectToCloneHandler,
36+
inventoryItemDeleteDeclinePriceHandler: deleteDeclinePriceHandler,
3537
//END V2
3638

3739
/**

server/handlers/v1/inventory/linnworks/inventoryItemAddPriceHandler.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ const { LINNWORKS } = require("../../../../../util/auditLog/logResourceTypes");
33

44
module.exports = (fastify) => ({
55
addPriceHandler: async (req, res) => {
6+
let _result,
7+
_error = false;
8+
69
const { itemInventoryPrices } = fastify.linnworks.formatters;
710
const { inventoryItemId, fieldValue, fieldName } = req.body;
811
let inventoryPrice = false;
@@ -25,15 +28,22 @@ module.exports = (fastify) => ({
2528
data: inventoryPrice,
2629
});
2730

28-
if (result) return { result, error: false };
29-
if (error) return { error, result: false };
31+
if (result) {
32+
_result = result;
33+
return { result, error: false };
34+
}
35+
36+
if (error) {
37+
_error = error;
38+
return { error, result: false };
39+
}
3040
} catch (error) {
3141
fastify.winston.error(error);
3242
} finally {
3343
fastify.auditLogger.log(
3444
ADD_PRICE_FIELD,
3545
req.user.id,
36-
fkStockItemId,
46+
inventoryItemId,
3747
LINNWORKS,
3848
JSON.stringify({
3949
_result,

0 commit comments

Comments
 (0)