|
|
@@ -40,6 +40,7 @@
|
|
|
function resetProductForm() {
|
|
|
productFormData = {
|
|
|
name: '',
|
|
|
+ description: '',
|
|
|
category: categories[0]?.name ?? '',
|
|
|
price: 0,
|
|
|
sendToKitchen: false
|
|
|
@@ -51,7 +52,12 @@
|
|
|
function handleProductSubmit(event) {
|
|
|
event.preventDefault();
|
|
|
|
|
|
- if (!productFormData.name || !productFormData.category || productFormData.price <= 0) {
|
|
|
+ if (
|
|
|
+ !productFormData.name ||
|
|
|
+ !productFormData.category ||
|
|
|
+ productFormData.price <= 0 ||
|
|
|
+ !productFormData.description
|
|
|
+ ) {
|
|
|
console.error('Preencha todos os campos corretamente');
|
|
|
return;
|
|
|
}
|
|
|
@@ -72,7 +78,10 @@
|
|
|
|
|
|
const requestOptions = {
|
|
|
method: 'POST',
|
|
|
- headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
+ Authorization: `Bearer ${token}`
|
|
|
+ },
|
|
|
body: JSON.stringify(payload),
|
|
|
redirect: 'follow'
|
|
|
};
|
|
|
@@ -81,8 +90,40 @@
|
|
|
.then((response) => response.json())
|
|
|
.then((res) => {
|
|
|
if (res.status === 'ok') {
|
|
|
+ const productId = res.data?.product_id;
|
|
|
+ if (!productId) {
|
|
|
+ console.error('Produto criado, mas ID não retornado.');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Chamada para adicionar a descrição
|
|
|
+ const descPayload = {
|
|
|
+ product_id: productId,
|
|
|
+ company_id: company,
|
|
|
+ description_text: productFormData.description
|
|
|
+ };
|
|
|
+
|
|
|
+ fetch('https://dev2.mixtech.dev.br/description/create', {
|
|
|
+ method: 'POST',
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
+ Authorization: `Bearer ${token}`
|
|
|
+ },
|
|
|
+ body: JSON.stringify(descPayload),
|
|
|
+ redirect: 'follow'
|
|
|
+ })
|
|
|
+ .then((descRes) => descRes.json())
|
|
|
+ .then((descResult) => {
|
|
|
+ if (descResult.status === 'ok') {
|
|
|
+ console.log('Descrição adicionada com sucesso!');
|
|
|
+ } else {
|
|
|
+ console.error('Erro ao adicionar descrição:', descResult.msg);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((error) => console.error('Erro na requisição de descrição:', error));
|
|
|
+
|
|
|
const newProduct = {
|
|
|
- id: res.data?.product_id || Date.now(),
|
|
|
+ id: productId,
|
|
|
...productFormData
|
|
|
};
|
|
|
products = [...products, newProduct];
|
|
|
@@ -431,8 +472,9 @@
|
|
|
<div>
|
|
|
<p class="mb-1 block text-sm text-gray-400">Descrição do Produto</p>
|
|
|
<input
|
|
|
+ bind:value={productFormData.description}
|
|
|
class="w-full rounded-md border border-gray-600 bg-gray-700 px-3 py-2 focus:ring-emerald-500"
|
|
|
- placeholder="Descricao"
|
|
|
+ placeholder="Descrição"
|
|
|
/>
|
|
|
</div>
|
|
|
|