Browse Source

Allow order URLs to be changed

master
Immanuel Onyeka 3 years ago
parent
commit
821ed7896c
6 changed files with 47 additions and 8 deletions
  1. +17
    -0
      app/Http/Controllers/OrderController.php
  2. +20
    -4
      resources/js/panel/order-item.vue
  3. +2
    -1
      resources/js/panel/orders.vue
  4. +1
    -2
      resources/js/panel/panel.vue
  5. +4
    -1
      resources/scss/main.scss
  6. +3
    -0
      routes/web.php

+ 17
- 0
app/Http/Controllers/OrderController.php View File

@@ -46,4 +46,21 @@ class OrderController extends Controller
} }
return true; return true;
} }

public function changeURL(Request $request) {
$validated = $request->validate([
'order' => 'required',
'url' => 'required'
]);

$order = Order::find($request->order);
$user = Auth::user();

if (!in_array($order->status, ['processing', 'error'])) {
abort(422);
}

$order->url = $request->url;
$order->save();
}
} }

+ 20
- 4
resources/js/panel/order-item.vue View File

@@ -16,7 +16,8 @@


<div class="details"> <div class="details">
<ul> <ul>
<li><b>Status:</b> <span>{{selected.status}}</span></li>
<li><b>Status:</b> <span>{{selected.status.charAt(0).toUpperCase() +
selected.status.slice(1)}}</span></li>
<li><b>Quantity:</b> <span>{{selected.quantity}}</span></li> <li><b>Quantity:</b> <span>{{selected.quantity}}</span></li>
<li><b>Remaining:</b> <span>{{selected.remaining}}</span></li> <li><b>Remaining:</b> <span>{{selected.remaining}}</span></li>
<li><b>URL:</b> <span>{{selected.url}}</span></li> <li><b>URL:</b> <span>{{selected.url}}</span></li>
@@ -26,8 +27,8 @@
<div v-if="selected.status == 'processing' || selected.status == <div v-if="selected.status == 'processing' || selected.status ==
'error'" class="change-url"> 'error'" class="change-url">
<h4>URL</h4> <h4>URL</h4>
<div><input :value="selected.url" type="url" id="url"></div>
<button @click="saveUrl" :disabled="loading">Save
<div><input v-model="url" type="url" id="url"></div>
<button @click="saveURL" :disabled="loading">Save
<loading-icon v-if="loading"></loading-icon></button> <loading-icon v-if="loading"></loading-icon></button>
<p id="overlay-error">{{errorMessage}}</p> <p id="overlay-error">{{errorMessage}}</p>
</div> </div>
@@ -41,15 +42,30 @@
import LoadingIcon from '../icons/loading.vue' import LoadingIcon from '../icons/loading.vue'


function saveURL() { function saveURL() {
fetch('/panel/save-url', {
method: 'POST',
headers: {'Content-Type': 'application/json',
'Accept': 'application/json',
'X-XSRF-TOKEN': this.token},
body: JSON.stringify({'url': this.url, 'order': this.selected.id})
}).then(response => {
if (response.ok) {
this.errorMessage = 'Saved'
this.$emit('changeUrl', this.url)
} else {
this.errorMessage = 'An error occured'
}
})


} }


export default { export default {
data() { data() {
return {loading: false, errorMessage: ''}
return {loading: false, errorMessage: '', url: this.selected.url}
}, },
components: {LoadingIcon}, components: {LoadingIcon},
methods: {saveURL}, methods: {saveURL},
props: ['selected', 'token'], props: ['selected', 'token'],
emits: ['changeUrl', 'close']
} }
</script> </script>

+ 2
- 1
resources/js/panel/orders.vue View File

@@ -47,7 +47,8 @@
src="../../images/arrow-right-circle-fill.svg" alt=""/> src="../../images/arrow-right-circle-fill.svg" alt=""/>
</section> </section>


<order-item @close="close" :selected="selected" :token="token"></order-item>
<order-item v-if="selected" @close="close" :selected="selected"
:token="token" @change-url="(url) => selected.url = url"></order-item>


</div> </div>
</template> </template>


+ 1
- 2
resources/js/panel/panel.vue View File

@@ -14,7 +14,7 @@
</section> </section>
<section class="recent-pane"><h4>Recent Activity</h4> <section class="recent-pane"><h4>Recent Activity</h4>
<table> <table>
<thead><th>Date</th><th>Name</th><th>Status</th> <th>Quantity</th></thead>
<thead><th>Date</th><th>Name</th><th>Status</th></thead>
<tbody> <tbody>
<tr v-bind:key='order.id' v-for='order in orders.slice(0, 10)'> <tr v-bind:key='order.id' v-for='order in orders.slice(0, 10)'>
<template v-if="order.status != 'pending'"> <template v-if="order.status != 'pending'">
@@ -23,7 +23,6 @@
<td :class="order.status" <td :class="order.status"
class="status"><span>{{order.status.charAt(0).toUpperCase() + class="status"><span>{{order.status.charAt(0).toUpperCase() +
order.status.slice(1)}}</span></td> order.status.slice(1)}}</span></td>
<td>{{order.quantity}}</td>
</template> </template>
</tr> </tr>
</tbody> </tbody>


+ 4
- 1
resources/scss/main.scss View File

@@ -804,7 +804,6 @@ section.recent-pane, section.history-pane{
border-spacing: 4px; border-spacing: 4px;
margin: auto; margin: auto;
text-align: center; text-align: center;
min-width: 30em;
width: 100%; width: 100%;
} }


@@ -913,6 +912,10 @@ section.recent-pane, section.history-pane{
left: 50%; left: 50%;
} }


table {
min-width: 30em;
}

} }


.actions { .actions {


+ 3
- 0
routes/web.php View File

@@ -131,6 +131,9 @@ Route::post('/panel/pm-fail', [BillingController::class,
Route::get('/panel/cards', [BillingController::class, Route::get('/panel/cards', [BillingController::class,
'getCards'])->middleware([ 'auth', 'verified' ]); 'getCards'])->middleware([ 'auth', 'verified' ]);


Route::post('/panel/save-url', [OrderController::class,
'changeURL'])->middleware([ 'auth', 'verified' ]);

//Stripe webhooks //Stripe webhooks
Route::post('/hooks/charge', Route::post('/hooks/charge',
[BillingController::class, 'chargeEvent']); [BillingController::class, 'chargeEvent']);


Loading…
Cancel
Save