2 lines
8.7 KiB
JavaScript
2 lines
8.7 KiB
JavaScript
import{j as e}from"./query-vendor-BLVqILA6.js";import{u as p,o as u,s}from"./form-vendor-vQotxSmE.js";import{a as y}from"./zod-7IfHMaWP.js";import{o as h,m as i,B as f,j,l as k,k as v,a0 as N,q as w,t as l}from"./ui-vendor-CyRvbSfR.js";import{T as _}from"./ThemeToggle-Cryh6OOS.js";import{u as S,s as z}from"./index-doec96Hx.js";import{useCurrentUser as E}from"./useUserStore-VOdYc7Zm.js";import{d as O,L as m}from"./router-vendor-D4by-_6Z.js";import"./react-vendor-CqRd3GwO.js";import"./supabase-vendor-CnnNSQLo.js";import"./state-vendor-DHadhBU5.js";const C=u({nome:s().min(3,"Nome deve ter pelo menos 3 caracteres"),descricao:s().optional(),endereco:s().optional(),cidade:s().optional(),estado:s().optional(),data_inicio:s().optional(),data_prevista_fim:s().optional(),responsavel_id:s().optional()});function V(){const g=O(),{user:T}=S(),d=E(),{register:r,handleSubmit:b,formState:{errors:n,isSubmitting:c}}=p({resolver:y(C),defaultValues:{data_inicio:new Date().toISOString().split("T")[0]}}),x=async a=>{try{if(!d?.organizacao_id){l.error("Erro: Organização não identificada. Tente fazer login novamente.");return}const t={nome:a.nome,descricao:a.descricao,endereco:a.endereco,cidade:a.cidade,estado:a.estado,data_inicio:a.data_inicio||null,data_prevista_fim:a.data_prevista_fim||null,status:"ativa",progresso_geral:0,configuracoes:{},responsavel_id:a.responsavel_id||d.id,organizacao_id:d.organizacao_id},{error:o}=await z.from("obras").insert(t);if(o)throw o;l.success("Obra criada com sucesso!"),g("/cadastros")}catch(t){const o=t instanceof Error?t.message:"Erro desconhecido";l.error(`Erro ao criar obra: ${o}`)}};return e.jsxs("div",{className:"min-h-screen bg-gradient-to-br from-blue-50 via-white to-purple-50 dark:from-gray-900 dark:via-gray-800 dark:to-gray-900",children:[e.jsx("div",{className:"bg-white/80 dark:bg-gray-800/80 backdrop-blur-md border-b border-gray-200/50 dark:border-gray-700/50 sticky top-0 z-10",children:e.jsxs("div",{className:"px-4 sm:px-6 py-4 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(m,{to:"/cadastros",className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-xl",children:e.jsx(h,{className:"w-5 h-5 text-gray-600 dark:text-gray-300"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold text-gray-900 dark:text-white",children:"Nova Obra"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-300",children:"Cadastre um novo empreendimento"})]})]}),e.jsx(_,{})]})}),e.jsx("div",{className:"max-w-4xl mx-auto p-4 sm:p-8",children:e.jsxs("form",{onSubmit:b(x),className:"space-y-6",children:[e.jsxs(i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"bg-white/70 dark:bg-gray-800/70 backdrop-blur-md rounded-2xl p-6 border border-gray-200/50 dark:border-gray-700/50 shadow-lg space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4 pb-4 border-b border-gray-100 dark:border-gray-700",children:[e.jsx("div",{className:"p-2 bg-blue-100 dark:bg-blue-900/30 rounded-lg",children:e.jsx(f,{className:"w-5 h-5 text-blue-600 dark:text-blue-400"})}),e.jsx("h3",{className:"font-semibold text-gray-900 dark:text-white",children:"Dados Principais"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Nome da Obra *"}),e.jsx("input",{type:"text",...r("nome"),className:"w-full p-3 bg-white/50 dark:bg-gray-700/50 border border-gray-300 dark:border-gray-600 rounded-xl focus:ring-2 focus:ring-blue-500 transition-all",placeholder:"Ex: Edifício Residencial Aurora"}),n.nome&&e.jsx("p",{className:"text-red-500 text-sm mt-1",children:n.nome.message})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Descrição"}),e.jsx("textarea",{...r("descricao"),rows:3,className:"w-full p-3 bg-white/50 dark:bg-gray-700/50 border border-gray-300 dark:border-gray-600 rounded-xl focus:ring-2 focus:ring-blue-500 transition-all",placeholder:"Breve descrição do projeto..."})]})]})]}),e.jsxs(i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:"bg-white/70 dark:bg-gray-800/70 backdrop-blur-md rounded-2xl p-6 border border-gray-200/50 dark:border-gray-700/50 shadow-lg space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4 pb-4 border-b border-gray-100 dark:border-gray-700",children:[e.jsx("div",{className:"p-2 bg-green-100 dark:bg-green-900/30 rounded-lg",children:e.jsx(j,{className:"w-5 h-5 text-green-600 dark:text-green-400"})}),e.jsx("h3",{className:"font-semibold text-gray-900 dark:text-white",children:"Localização"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Endereço"}),e.jsx("input",{type:"text",...r("endereco"),className:"w-full p-3 bg-white/50 dark:bg-gray-700/50 border border-gray-300 dark:border-gray-600 rounded-xl focus:ring-2 focus:ring-blue-500 transition-all",placeholder:"Rua, número, bairro..."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Cidade"}),e.jsx("input",{type:"text",...r("cidade"),className:"w-full p-3 bg-white/50 dark:bg-gray-700/50 border border-gray-300 dark:border-gray-600 rounded-xl focus:ring-2 focus:ring-blue-500 transition-all"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Estado"}),e.jsx("input",{type:"text",...r("estado"),className:"w-full p-3 bg-white/50 dark:bg-gray-700/50 border border-gray-300 dark:border-gray-600 rounded-xl focus:ring-2 focus:ring-blue-500 transition-all",placeholder:"UF",maxLength:2})]})]})]}),e.jsxs(i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.2},className:"bg-white/70 dark:bg-gray-800/70 backdrop-blur-md rounded-2xl p-6 border border-gray-200/50 dark:border-gray-700/50 shadow-lg space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4 pb-4 border-b border-gray-100 dark:border-gray-700",children:[e.jsx("div",{className:"p-2 bg-purple-100 dark:bg-purple-900/30 rounded-lg",children:e.jsx(k,{className:"w-5 h-5 text-purple-600 dark:text-purple-400"})}),e.jsx("h3",{className:"font-semibold text-gray-900 dark:text-white",children:"Prazos e Responsáveis"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Data de Início"}),e.jsx("input",{type:"date",...r("data_inicio"),className:"w-full p-3 bg-white/50 dark:bg-gray-700/50 border border-gray-300 dark:border-gray-600 rounded-xl focus:ring-2 focus:ring-blue-500 transition-all"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Previsão de Término"}),e.jsx("input",{type:"date",...r("data_prevista_fim"),className:"w-full p-3 bg-white/50 dark:bg-gray-700/50 border border-gray-300 dark:border-gray-600 rounded-xl focus:ring-2 focus:ring-blue-500 transition-all"})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"ID do Responsável (Opcional)"}),e.jsxs("div",{className:"relative",children:[e.jsx(v,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400"}),e.jsx("input",{type:"text",...r("responsavel_id"),className:"w-full pl-10 p-3 bg-white/50 dark:bg-gray-700/50 border border-gray-300 dark:border-gray-600 rounded-xl focus:ring-2 focus:ring-blue-500 transition-all",placeholder:"UUID do usuário responsável"})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"Se vazio, será atribuído ao seu usuário."})]})]})]}),e.jsxs("div",{className:"flex gap-4 pt-4",children:[e.jsx(m,{to:"/cadastros",className:"flex-1 py-3 px-4 rounded-xl border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-800 flex items-center justify-center gap-2 font-medium transition-colors",children:"Cancelar"}),e.jsx("button",{type:"submit",disabled:c,className:"flex-1 py-3 px-4 rounded-xl bg-blue-600 text-white hover:bg-blue-700 flex items-center justify-center gap-2 font-medium shadow-lg shadow-blue-500/30 transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:c?e.jsxs(e.Fragment,{children:[e.jsx(N,{className:"w-5 h-5 animate-spin"}),"Salvando..."]}):e.jsxs(e.Fragment,{children:[e.jsx(w,{className:"w-5 h-5"}),"Salvar Obra"]})})]})]})})]})}export{V as default};
|