Movida logica de obtener sesion a subpedido select + simplificado elegir pedido + mejores responses de session controller
This commit is contained in:
parent
354045c5df
commit
8488d9d6c5
4 changed files with 48 additions and 27 deletions
|
@ -3,13 +3,16 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Subpedido;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class SessionController extends Controller
|
||||
{
|
||||
public function store(Request $request) {
|
||||
public function store(Request $request): Response
|
||||
{
|
||||
$grupo_de_compra_id = Auth::user()->grupo_de_compra_id;
|
||||
$validated = $request->validate([
|
||||
'id' => 'required',
|
||||
|
@ -19,11 +22,14 @@ class SessionController extends Controller
|
|||
return response()->noContent();
|
||||
}
|
||||
|
||||
public function fetch() {
|
||||
return session('pedido_id');
|
||||
public function fetch(): JsonResponse
|
||||
{
|
||||
return response()->json(['id' => session('pedido_id')]);
|
||||
}
|
||||
|
||||
public function destroy() {
|
||||
public function destroy(): Response
|
||||
{
|
||||
session()->forget('pedido_id');
|
||||
return response()->noContent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
|
||||
<script>
|
||||
import { mapActions, mapGetters } from "vuex";
|
||||
import CartelPedidoAprobado from "./CartelPedidoAprobado.vue";
|
||||
import PedidoSelectSection from "./PedidoSelectSection.vue";
|
||||
import Pedido from "./Pedido.vue";
|
||||
import CartelPedidoAprobado from "./CartelPedidoAprobado.vue";
|
||||
|
||||
export default {
|
||||
components: { CartelPedidoAprobado, Pedido, Productos: Pedido, PedidoSelectSection },
|
||||
|
@ -19,11 +19,9 @@ export default {
|
|||
},
|
||||
methods: {
|
||||
...mapActions('productos',["init"]),
|
||||
...mapActions('pedido',["getSesion"]),
|
||||
},
|
||||
async mounted() {
|
||||
await this.init();
|
||||
await this.getSesion();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -11,21 +11,30 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="column is-one-third buttons">
|
||||
<button class="button is-danger" v-if="!deshabilitado" @click="submit">Crear nuevo pedido
|
||||
<button class="button is-danger" v-if="!deshabilitado" @click="submit(undefined)">
|
||||
Crear nuevo pedido
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="pedidos.length" class="block">
|
||||
<label class="label">Si ya comenzaste a hacer tu pedido este mes, elegilo en esta lista:</label>
|
||||
<p class="help">Podés seguir escribiendo en el campo de arriba para refinar la búsqueda.</p>
|
||||
<div class="columns is-mobile" v-for="(subpedidoExistente, index) in pedidos"
|
||||
:class="{'has-background-grey-lighter': index % 2}" :key="index">
|
||||
<label class="label">
|
||||
Si ya comenzaste a hacer tu pedido este mes, elegilo en esta lista:
|
||||
</label>
|
||||
<p class="help">
|
||||
Podés seguir escribiendo en el campo de arriba para refinar la búsqueda.
|
||||
</p>
|
||||
<div class="columns is-mobile"
|
||||
v-for="(subpedidoExistente, index) in pedidos"
|
||||
:class="{'has-background-grey-lighter': index % 2}"
|
||||
:key="index">
|
||||
<div class="column is-half-mobile is-two-thirds-desktop is-two-thirds-tablet">
|
||||
<p style="padding-top: calc(.5em - 1px); margin-bottom: .5rem"
|
||||
v-text="subpedidoExistente.nombre"></p>
|
||||
<p class="nombre">
|
||||
{{ subpedidoExistente.nombre }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="buttons column is-half-mobile is-one-third-desktop is-one-third-tablet">
|
||||
<button class="button is-danger" @click="elegirPedido({ pedido: subpedidoExistente })">Continuar pedido
|
||||
<button class="button is-danger" @click="submit(subpedidoExistente)">
|
||||
Continuar pedido
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -35,11 +44,16 @@
|
|||
|
||||
<script>
|
||||
import { mapActions, mapMutations, mapState } from "vuex";
|
||||
import axios from "axios";
|
||||
|
||||
export default {
|
||||
name: 'SubpedidoSelect',
|
||||
async mounted() {
|
||||
await this.getGrupoDeCompra();
|
||||
const sesion = await axios.get("/pedido/sesion");
|
||||
if (sesion.data.id) {
|
||||
await this.elegirPedido({ pedido_id: sesion.data.id });
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
@ -64,9 +78,19 @@ export default {
|
|||
}
|
||||
this.getPedidos(this.searchString);
|
||||
},
|
||||
async submit() {
|
||||
await this.crearPedido({ nombre: this.searchString, grupo_de_compra_id: this.grupo_de_compra_id });
|
||||
async submit(pedido) {
|
||||
if (pedido)
|
||||
await this.elegirPedido({ pedido_id: pedido.id });
|
||||
else
|
||||
await this.crearPedido({ nombre: this.searchString, grupo_de_compra_id: this.grupo_de_compra_id });
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.nombre {
|
||||
padding-top: calc(.5em - 1px);
|
||||
margin-bottom: .5rem
|
||||
}
|
||||
</style>
|
||||
|
|
13
resources/js/store/modules/pedido.js
vendored
13
resources/js/store/modules/pedido.js
vendored
|
@ -47,13 +47,6 @@ const actions = {
|
|||
async guardarSesion(_, { pedido_id }) {
|
||||
await axios.post("/pedido/sesion", { id: pedido_id });
|
||||
},
|
||||
async getSesion({ commit }) {
|
||||
const sesion = await axios.get("/pedido/sesion");
|
||||
if (sesion.data) {
|
||||
const response = await axios.get(`/api/subpedidos/${sesion.data}`);
|
||||
commit('setPedido', response.data.data);
|
||||
}
|
||||
},
|
||||
async crearPedido({ commit, dispatch }, { nombre, grupo_de_compra_id }) {
|
||||
const response = await axios.post("/api/subpedidos", {
|
||||
nombre: nombre,
|
||||
|
@ -62,9 +55,9 @@ const actions = {
|
|||
dispatch("guardarSesion", { pedido_id: response.data.data.id});
|
||||
commit('setPedido', response.data.data);
|
||||
},
|
||||
async elegirPedido({ commit, dispatch }, { pedido }) {
|
||||
const response = await axios.get(`/api/subpedidos/${pedido.id}`);
|
||||
dispatch("guardarSesion", { pedido_id: response.data.data.id})
|
||||
async elegirPedido({ commit, dispatch }, { pedido_id }) {
|
||||
const response = await axios.get(`/api/subpedidos/${pedido_id}`);
|
||||
dispatch("guardarSesion", { pedido_id: pedido_id})
|
||||
commit('setPedido', response.data.data);
|
||||
},
|
||||
async modificarChismosa({ commit, dispatch }, { producto_id, cantidad, notas }) {
|
||||
|
|
Loading…
Add table
Reference in a new issue