@lancom/shared 0.0.193 → 0.0.195

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -362,6 +362,36 @@ export default {
362
362
  removeWebhook(id) {
363
363
  return _delete(`admin/webhooks/${id}`);
364
364
  },
365
+ async fetchCurrencies(params) {
366
+ return sortByName(await _get('admin/currencies', params));
367
+ },
368
+ fetchCurrencyById(id) {
369
+ return _get(`admin/currencies/${id}`);
370
+ },
371
+ saveCurrency(currency) {
372
+ return currency._id ? _put(`admin/currencies/${currency._id}`, currency) : _post('admin/currencies', currency);
373
+ },
374
+ removeCurrency(id) {
375
+ return _delete(`admin/currencies/${id}`);
376
+ },
377
+ async fetchCurrencies(params) {
378
+ return sortByName(await _get('admin/currencies', params));
379
+ },
380
+ async fetchCountries(params) {
381
+ return sortByName(await _get('admin/countries', params));
382
+ },
383
+ fetchCountryById(id) {
384
+ return _get(`admin/countries/${id}`);
385
+ },
386
+ saveCountry(country) {
387
+ return country._id ? _put(`admin/countries/${country._id}`, country) : _post('admin/countries', country);
388
+ },
389
+ removeCountry(id) {
390
+ return _delete(`admin/countries/${id}`);
391
+ },
392
+ async fetchCountries(params) {
393
+ return sortByName(await _get('admin/countries', params));
394
+ },
365
395
  async fetchWarehouses(params) {
366
396
  return sortByName(await _get('admin/warehouse', params));
367
397
  },
@@ -3,6 +3,9 @@ import { _get, _post, _put, _delete, _patch } from './helpers';
3
3
  import adminApi from './admin';
4
4
 
5
5
  const api = {
6
+ fetchClientSettings(shop, params) {
7
+ return _get(`shop/${shop}/client-settings`, params);
8
+ },
6
9
  fetchCartById(shop, cart) {
7
10
  return _get(`shop/${shop}/cart/${cart}`);
8
11
  },
@@ -0,0 +1,54 @@
1
+ @import "@/assets/scss/variables";
2
+ .ClientSettings {
3
+ &__wrapper {
4
+ position: relative;
5
+ }
6
+ &__field {
7
+ padding: 6px !important;
8
+ height: 50px;
9
+ display: flex !important;
10
+ align-items: center;
11
+ cursor: pointer;
12
+ }
13
+ &__inner {
14
+ min-width: 72px;
15
+ width: 33%;
16
+ height: 100%;
17
+ border-radius: 2px;
18
+ box-shadow: $elevation1;
19
+ }
20
+ &__value {
21
+ color: $grey_1;
22
+ text-transform: uppercase;
23
+ margin-left: 20px;
24
+ flex-grow: 1;
25
+ }
26
+ &__caret {
27
+ color: $grey_5;
28
+ font-size: 18px;
29
+ cursor: pointer;
30
+ }
31
+ &__dropdown {
32
+ position: absolute;
33
+ z-index: 101;
34
+ top: 40px;
35
+ width: 250px;
36
+ // transform: translateY(-50%);
37
+ padding: 10px;
38
+ box-shadow: 0 0 2px grey;
39
+ background-color: white;
40
+ }
41
+ &__field {
42
+ padding: 10px 0;
43
+ display: flex;
44
+ justify-content: space-between;
45
+ cursor: pointer;
46
+ &-item {
47
+ padding: 7px 10px;
48
+ cursor: pointer;
49
+ &:hover {
50
+ background-color: $grey_3;
51
+ }
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,106 @@
1
+ <template>
2
+ <div class="ClientSettings__wrapper">
3
+ <div
4
+ class="ClientSettings__field"
5
+ @click="isOpen = !isOpen">
6
+ <div class="lc_regular16 ClientSettings__value">
7
+ <div class="d-flex">
8
+ <span v-if="country">
9
+ {{ country.isoCode }}
10
+ </span>
11
+ <span v-if="currency">
12
+ / {{ currency.symbol }}
13
+ </span>
14
+ </div>
15
+ </div>
16
+ <i class="icon-angle-down ClientSettings__caret"></i>
17
+ </div>
18
+ <div
19
+ v-if="isOpen"
20
+ v-click-outside="close"
21
+ class="ClientSettings__dropdown">
22
+ <div>
23
+ <div
24
+ class="ClientSettings__field"
25
+ @click="toggleVisibleCountries()">
26
+ <span>{{ country.name }}</span>
27
+ <i class="icon-angle-down"></i>
28
+ </div>
29
+ <div v-if="visibleCountries">
30
+ <div
31
+ v-for="item of countries"
32
+ :key="item._id"
33
+ class="ClientSettings__field-item"
34
+ @click="selectCountry(item)">
35
+ {{ item.name }}
36
+ </div>
37
+ </div>
38
+ </div>
39
+ <div>
40
+ <div
41
+ class="ClientSettings__field"
42
+ @click="toggleVisibleCurrencies()">
43
+ <span>{{ currency.name }}, {{ currency.symbol }}</span>
44
+ <i class="icon-angle-down"></i>
45
+ </div>
46
+ <div v-if="visibleCurrencies">
47
+ <div
48
+ v-for="item of currencies"
49
+ :key="item._id"
50
+ class="ClientSettings__field-item"
51
+ @click="selectCurrency(item)">
52
+ {{ item.symbol }}, {{ item.name }}
53
+ </div>
54
+ </div>
55
+ </div>
56
+ </div>
57
+ </div>
58
+ </template>
59
+
60
+ <script>
61
+ import { mapGetters } from 'vuex';
62
+ const Cookie = process.client ? require('js-cookie') : undefined;
63
+
64
+ export default {
65
+ name: 'ClientSettings',
66
+ data() {
67
+ return {
68
+ isOpen: false,
69
+ visibleCountries: false,
70
+ visibleCurrencies: false
71
+ };
72
+ },
73
+ computed: {
74
+ ...mapGetters([
75
+ 'country',
76
+ 'currency',
77
+ 'countries',
78
+ 'currencies'
79
+ ]),
80
+ },
81
+ methods: {
82
+ close() {
83
+ this.isOpen = false;
84
+ },
85
+ toggleVisibleCountries() {
86
+ this.visibleCountries = !this.visibleCountries;
87
+ },
88
+ toggleVisibleCurrencies() {
89
+ this.visibleCurrencies = !this.visibleCurrencies;
90
+ },
91
+ selectCountry(country) {
92
+ Cookie.set('country', country._id);
93
+ window.location.reload();
94
+ },
95
+ selectCurrency(currency) {
96
+ Cookie.set('currency', currency._id);
97
+ window.location.reload();
98
+ }
99
+ }
100
+ };
101
+ </script>
102
+
103
+ <style lang="scss">
104
+ @import 'client-settings';
105
+ </style>
106
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lancom/shared",
3
- "version": "0.0.193",
3
+ "version": "0.0.195",
4
4
  "description": "lancom common scripts",
5
5
  "author": "e.tokovenko <e.tokovenko@gmail.com>",
6
6
  "repository": {
package/store/index.js CHANGED
@@ -4,6 +4,8 @@ const cookieparser = process.server ? require('cookieparser') : undefined;
4
4
  const CLOSED_NOTIFICATION = 'lancom-closed-notification-1.0';
5
5
 
6
6
  export const state = () => ({
7
+ country: null,
8
+ currency: null,
7
9
  shop: {},
8
10
  menus: [],
9
11
  contacts: {},
@@ -16,6 +18,10 @@ export const state = () => ({
16
18
  });
17
19
 
18
20
  export const getters = {
21
+ country: ({ country }) => country,
22
+ countries: ({ shop }) => (shop.countries || []).map(({ country }) => country).filter(c => !!c),
23
+ currency: ({ currency }) => currency,
24
+ currencies: ({ shop }) => (shop.countries || []).reduce((currencies, { country }) => [...currencies, country?.currency], []).filter(c => !!c),
19
25
  shop: ({ shop }) => shop || {},
20
26
  menus: ({ menus }) => menus || [],
21
27
  topMenu: ({ menus }) => (menus || []).find(({ type }) => type === 'top'),
@@ -39,7 +45,13 @@ export const actions = {
39
45
  commit('setMenus', menus);
40
46
  commit('setShop', shop);
41
47
  commit('setSettings', shop.settings);
42
-
48
+ if (req.headers.cookie) {
49
+ const { country, currency } = cookieparser.parse(req.headers.cookie);
50
+ const params = { country, currency, ip: req.ip };
51
+ const settings = await api.fetchClientSettings(shop._id, params);
52
+ commit('setCountry', settings.country);
53
+ commit('setCurrency', settings.currency);
54
+ }
43
55
  try {
44
56
  if (req.headers.cookie) {
45
57
  const { auth } = cookieparser.parse(req.headers.cookie);
@@ -82,6 +94,12 @@ export const actions = {
82
94
  };
83
95
 
84
96
  export const mutations = {
97
+ setCountry(state, country) {
98
+ state.country = country;
99
+ },
100
+ setCurrency(state, currency) {
101
+ state.currency = currency;
102
+ },
85
103
  setSettings(state, { contacts, pricing, notificationBar, discountPopup, order, depositInfo }) {
86
104
  state.contacts = contacts;
87
105
  state.pricing = pricing;