Download src/components/admin/ProdutoForm.jsx from guisousa/BaseAdmin: direct link, hf CLI and curl.
- Browser
- Download file 5.61 kB
-
https://huggingface.co/spaces/guisousa/BaseAdmin/resolve/main/src/components/admin/ProdutoForm.jsx
- Command line
-
hf download hf://spaces/guisousa/BaseAdmin/src/components/admin/ProdutoForm.jsx
-
curl -L -o ProdutoForm.jsx https://huggingface.co/spaces/guisousa/BaseAdmin/resolve/main/src/components/admin/ProdutoForm.jsx
5.61 kB
| import React, { useState } from "react"; | |
| import { motion } from "framer-motion"; | |
| import { Card, CardContent, CardHeader, CardTitle, CardFooter } from "@/components/ui/card"; | |
| import { Button } from "@/components/ui/button"; | |
| import { Input } from "@/components/ui/input"; | |
| import { Label } from "@/components/ui/label"; | |
| import { Textarea } from "@/components/ui/textarea"; | |
| import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; | |
| import { Checkbox } from "@/components/ui/checkbox"; | |
| import { base44 } from "@/api/base44Client"; | |
| export default function ProdutoForm({ produto, onSubmit, onCancel, isLoading }) { | |
| const [formData, setFormData] = useState(produto || { | |
| nome: "", | |
| descricao: "", | |
| preco: "", | |
| estoque: "", | |
| imagem_url: "", | |
| categoria: "outros", | |
| ativo: true, | |
| }); | |
| const [uploading, setUploading] = useState(false); | |
| const handleFileUpload = async (e) => { | |
| const file = e.target.files[0]; | |
| if (!file) return; | |
| setUploading(true); | |
| const { file_url } = await base44.integrations.Core.UploadFile({ file }); | |
| setFormData({ ...formData, imagem_url: file_url }); | |
| setUploading(false); | |
| }; | |
| const handleSubmit = (e) => { | |
| e.preventDefault(); | |
| onSubmit({ | |
| ...formData, | |
| preco: parseFloat(formData.preco), | |
| estoque: parseInt(formData.estoque), | |
| }); | |
| }; | |
| return ( | |
| <motion.div | |
| initial={{ opacity: 0, y: -20 }} | |
| animate={{ opacity: 1, y: 0 }} | |
| exit={{ opacity: 0, y: -20 }} | |
| > | |
| <Card className="mb-8 border-2 border-black"> | |
| <CardHeader className="bg-black text-white"> | |
| <CardTitle>{produto ? "Editar Produto" : "Novo Produto"}</CardTitle> | |
| </CardHeader> | |
| <form onSubmit={handleSubmit}> | |
| <CardContent className="p-6 space-y-4"> | |
| <div className="grid md:grid-cols-2 gap-4"> | |
| <div className="space-y-2"> | |
| <Label>Nome do Produto *</Label> | |
| <Input | |
| value={formData.nome} | |
| onChange={(e) => setFormData({ ...formData, nome: e.target.value })} | |
| required | |
| /> | |
| </div> | |
| <div className="space-y-2"> | |
| <Label>Categoria *</Label> | |
| <Select | |
| value={formData.categoria} | |
| onValueChange={(value) => setFormData({ ...formData, categoria: value })} | |
| > | |
| <SelectTrigger> | |
| <SelectValue /> | |
| </SelectTrigger> | |
| <SelectContent> | |
| <SelectItem value="pomada">Pomada</SelectItem> | |
| <SelectItem value="cera">Cera</SelectItem> | |
| <SelectItem value="shampoo">Shampoo</SelectItem> | |
| <SelectItem value="oleo">Óleo</SelectItem> | |
| <SelectItem value="navalha">Navalha</SelectItem> | |
| <SelectItem value="outros">Outros</SelectItem> | |
| </SelectContent> | |
| </Select> | |
| </div> | |
| </div> | |
| <div className="grid md:grid-cols-2 gap-4"> | |
| <div className="space-y-2"> | |
| <Label>Preço (R$) *</Label> | |
| <Input | |
| type="number" | |
| step="0.01" | |
| value={formData.preco} | |
| onChange={(e) => setFormData({ ...formData, preco: e.target.value })} | |
| required | |
| /> | |
| </div> | |
| <div className="space-y-2"> | |
| <Label>Estoque *</Label> | |
| <Input | |
| type="number" | |
| value={formData.estoque} | |
| onChange={(e) => setFormData({ ...formData, estoque: e.target.value })} | |
| required | |
| /> | |
| </div> | |
| </div> | |
| <div className="space-y-2"> | |
| <Label>Imagem do Produto</Label> | |
| <Input | |
| type="file" | |
| accept="image/*" | |
| onChange={handleFileUpload} | |
| disabled={uploading} | |
| /> | |
| {uploading && <p className="text-sm text-gray-500">Enviando...</p>} | |
| {formData.imagem_url && ( | |
| <img src={formData.imagem_url} alt="Preview" className="w-32 h-32 object-cover rounded-lg mt-2" /> | |
| )} | |
| </div> | |
| <div className="space-y-2"> | |
| <Label>Descrição</Label> | |
| <Textarea | |
| value={formData.descricao} | |
| onChange={(e) => setFormData({ ...formData, descricao: e.target.value })} | |
| rows={3} | |
| /> | |
| </div> | |
| <div className="flex items-center space-x-2"> | |
| <Checkbox | |
| id="ativo" | |
| checked={formData.ativo} | |
| onCheckedChange={(checked) => setFormData({ ...formData, ativo: checked })} | |
| /> | |
| <label htmlFor="ativo" className="text-sm cursor-pointer"> | |
| Produto ativo (visível na loja) | |
| </label> | |
| </div> | |
| </CardContent> | |
| <CardFooter className="flex justify-end gap-3 border-t p-6"> | |
| <Button type="button" variant="outline" onClick={onCancel}> | |
| Cancelar | |
| </Button> | |
| <Button type="submit" className="bg-black hover:bg-gray-800 text-white" disabled={isLoading}> | |
| {isLoading ? "Salvando..." : "Salvar"} | |
| </Button> | |
| </CardFooter> | |
| </form> | |
| </Card> | |
| </motion.div> | |
| ); | |
| } |