This commit is contained in:
j3d1 2024-06-18 16:43:23 +02:00
parent 5af3e72218
commit 804c47a3b8
9 changed files with 66 additions and 182 deletions

View file

@ -1,91 +0,0 @@
<template>
<div class="timeline-item-description">
<i class="avatar | small">
<font-awesome-icon icon="user"/>
</i>
<span><a href="#">$USER</a> has claimed sipping code
<ClipboardButton class="btn btn-primary badge badge-pill" title="Copy shipping code to clipboard" :payload="item.code">{{ item.code }}
<font-awesome-icon icon="clipboard"/>
</ClipboardButton> of type <span class="badge badge-pill badge-secondary">{{ item.code_type }}</span> for this ticket at <time
:datetime="timestamp">{{ timestamp }}</time>
</span>
</div>
</template>
<script>
import {mapState} from "vuex";
import ClipboardButton from "@/components/inputs/ClipboardButton.vue";
export default {
name: 'TimelineShippingCode',
components: {ClipboardButton},
props: {
'item': {
type: Object,
required: true
}
},
computed: {
...mapState(['state_options']),
'timestamp': function () {
return new Date(this.item.timestamp).toLocaleString();
},
}
};
</script>
<style scoped>
a {
color: inherit;
}
.timeline-item-description {
display: flex;
padding-top: 6px;
gap: 8px;
color: var(--gray);
img {
flex-shrink: 0;
}
a {
/*color: var(--c-grey-500);*/
font-weight: 500;
text-decoration: none;
&:hover,
&:focus {
outline: 0; /* Don't actually do this */
color: var(--info);
}
}
}
.avatar {
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
overflow: hidden;
aspect-ratio: 1 / 1;
flex-shrink: 0;
width: 40px;
height: 40px;
&.small {
width: 28px;
height: 28px;
}
img {
object-fit: cover;
}
}
</style>

View file

@ -21,7 +21,7 @@ const store = createStore({
state_options: [],
messageTemplates: [],
messageTemplateVariables: [],
shippingCodes: [],
shippingVouchers: [],
lastEvent: '37C3',
lastUsed: {},
@ -51,7 +51,7 @@ const store = createStore({
showAddBoxModal: false,
test: ['foo', 'bar', 'baz'],
shippingCodeTypes: {
shippingVoucherTypes: {
'2kg-de': '2kg Paket (DE)',
'5kg-de': '5kg Paket (DE)',
'10kg-de': '10kg Paket (DE)',
@ -219,8 +219,8 @@ const store = createStore({
setMessageTemplateVariables(state, variables) {
state.messageTemplateVariables = variables;
},
setShippingCodes(state, codes) {
state.shippingCodes = codes;
setShippingVouchers(state, codes) {
state.shippingVouchers = codes;
},
},
actions: {
@ -465,16 +465,16 @@ const store = createStore({
dispatch('fetchMessageTemplates');
}
},
async fetchShippingCodes({commit, state}) {
const {data, success} = await http.get('/2/shipping_codes/', state.user.token);
async fetchShippingVouchers({commit, state}) {
const {data, success} = await http.get('/2/shipping_vouchers/', state.user.token);
if (data && success) {
commit('setShippingCodes', data);
commit('setShippingVouchers', data);
}
},
async createShippingCode({dispatch, state}, code) {
const {data, success} = await http.post('/2/shipping_codes/', code, state.user.token);
async createShippingVoucher({dispatch, state}, code) {
const {data, success} = await http.post('/2/shipping_vouchers/', code, state.user.token);
if (data && success) {
dispatch('fetchShippingCodes');
dispatch('fetchShippingVouchers');
}
}
},
@ -506,7 +506,7 @@ const store = createStore({
"loadedItems",
"messageTemplates",
"messageTemplatesVariables",
"shippingCodes",
"shippingVouchers",
],
watch: [
"test",
@ -519,7 +519,7 @@ const store = createStore({
"loadedItems",
"messageTemplates",
"messageTemplatesVariables",
"shippingCodes",
"shippingVouchers",
],
mutations: [
//"replaceTickets",

View file

@ -1,9 +1,9 @@
<template>
<div>
<h3>Shipping Codes</h3>
<h3>Shipping Vouchers</h3>
<div class="mt-3">
<h5>Shipping Code Types</h5>
<span v-for="(type, key) in availableShippingCodeTypes()" :key="key" class="mr-2">
<h5>Shipping Voucher Types</h5>
<span v-for="(type, key) in availableShippingVoucherTypes()" :key="key" class="mr-2">
<span v-if="type.count > 2" class="badge badge-success">{{ type.name }} - {{ type.count }}</span>
<span v-else-if="type.count > 0" class="badge badge-warning" v-if="type.count > 0">
{{ type.name }} - {{ type.count }}
@ -12,23 +12,23 @@
</span>
</div>
<div class="mt-3">
<h5>Available Shipping Codes</h5>
<h5>Available Shipping Vouchers</h5>
<ul>
<li v-for="code in shippingCodes" :key="code.code">
<span v-if="code.issue_thread == null">{{ code.type }} - {{ code.code }}</span>
<span v-else><s style="color:var(--danger)">{{ code.type }} - {{ code.code }}</s> use in <a
:href="'/'+ getEventSlug + '/ticket/' + code.issue_thread">#{{ code.issue_thread }}</a></span>
<li v-for="voucher in shippingVouchers" :key="voucher.voucher">
<span v-if="voucher.issue_thread == null">{{ voucher.type }} - {{ voucher.voucher }}</span>
<span v-else><s style="color:var(--danger)">{{ voucher.type }} - {{ voucher.voucher }}</s> used in <a
:href="'/'+ getEventSlug + '/ticket/' + voucher.issue_thread">#{{ voucher.issue_thread }}</a></span>
</li>
</ul>
</div>
<div class="mt-3">
<textarea class="form-control mb-3" rows="5" placeholder="Shipping Code List" v-model="bulk_codes"
<textarea class="form-control mb-3" rows="5" placeholder="Shipping Voucher List" v-model="bulk_vouchers"
v-if="bulk"></textarea>
<div class="input-group">
<input type="text" class="form-control" placeholder="Shipping Code" v-model="code" v-if="!bulk">
<input type="text" class="form-control" placeholder="Shipping Voucher" v-model="voucher" v-if="!bulk">
<select class="form-control" v-model="type">
<option v-for="it in Object.keys(shippingCodeTypes)" :value="it">{{
shippingCodeTypes[it]
<option v-for="it in Object.keys(shippingVoucherTypes)" :value="it">{{
shippingVoucherTypes[it]
}}
</option>
</select>
@ -38,9 +38,9 @@
<label for="bulk" style="margin: 0;">Bulk</label>
</div>
</div>
<button class="btn btn-primary form-control" @click="createSingleOrBulkShippingCode">
<button class="btn btn-primary form-control" @click="createSingleOrBulkShippingVoucher">
<font-awesome-icon icon="plus"/>
{{ (bulk ? "Add Shipping Codes" : "Add Shipping Code") }}
{{ (bulk ? "Add Shipping Vouchers" : "Add Shipping Voucher") }}
</button>
</div>
</div>
@ -56,44 +56,44 @@ export default {
components: {Table},
data() {
return {
code: '',
bulk_codes: '',
voucher: '',
bulk_vouchers: '',
type: '2kg-eu',
bulk: false,
};
},
computed: {
...mapState(['shippingCodes', 'shippingCodeTypes']),
...mapState(['shippingVouchers', 'shippingVoucherTypes']),
...mapGetters(['getEventSlug']),
},
methods: {
...mapActions(['fetchShippingCodes', 'createShippingCode']),
createSingleOrBulkShippingCode() {
...mapActions(['fetchShippingVouchers', 'createShippingVoucher']),
createSingleOrBulkShippingVoucher() {
if (this.bulk) {
const list = this.bulk_codes.split('\n');
if (confirm('Are you sure you want to add ' + list.length + ' shipping codes as ' + this.type + '?')) {
const jobs = list.map(code => {
return this.createShippingCode({code: code.trim(), type: this.type});
const list = this.bulk_vouchers.split('\n');
if (confirm('Are you sure you want to add ' + list.length + ' shipping vouchers as ' + this.type + '?')) {
const jobs = list.map(voucher => {
return this.createShippingVoucher({voucher: voucher.trim(), type: this.type});
});
Promise.all(jobs).then(() => {
this.bulk_codes = '';
this.bulk_vouchers = '';
});
}
} else {
this.createShippingCode({code: this.code, type: this.type}).then(() => {
this.code = '';
this.createShippingVoucher({voucher: this.voucher, type: this.type}).then(() => {
this.voucher = '';
});
}
},
availableShippingCodeTypes() {
return Object.keys(this.shippingCodeTypes).map(key => {
var count = this.shippingCodes.filter(code => code.type === key && code.issue_thread === null).length;
return {id: key, count: count, name: this.shippingCodeTypes[key]};
availableShippingVoucherTypes() {
return Object.keys(this.shippingVoucherTypes).map(key => {
var count = this.shippingVouchers.filter(voucher => voucher.type === key && voucher.issue_thread === null).length;
return {id: key, count: count, name: this.shippingVoucherTypes[key]};
});
},
},
mounted() {
this.fetchShippingCodes();
this.fetchShippingVouchers();
},
};
</script>