Criando uma automação de documentos #2524
BrunoRV01
started this conversation in
Mostre seu trabalho
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
senhores, estou fazendo uma automação pra minha instituição, mas o code não está querendo funcionar de jeito nenhum. Diz que é o react, mas já instalei as coisas, diz que é o JSX, mas instalei tmb, mudei os terminais e mesmo assim continua não funcionando. E ele ta gritando o vermelho nos reacts e não sei mais o que fazer. Alguém me helpa aqui plmds
import React from 'react';
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
import { Save, FileOutput, Printer, Plus, Minus } from 'lucide-react';
import { MILITARY_TEMPLATES, MILITARY_RANKS, MILITARY_FUNCTIONS } from '../types/militaryTemplates';
const documentSchema = z.object({
documentType: z.enum(['PARTE', 'OFICIO', 'MEMORANDO', 'REQUERIMENTO', 'ATESTADO', 'CERTIDAO', 'DESPACHO',
'INFORMACAO', 'ORDEM_SERVICO', 'TERMO_JUNTADA', 'TERMO_DESENTRANHAMENTO', 'TERMO_INCORPORACAO',
'TERMO_DESINCORPORACAO', 'TERMO_APENSAMENTO', 'TERMO_ENCERRAMENTO']),
number: z.string(),
date: z.string().min(1, 'Data é obrigatória'),
classification: z.enum(['OSTENSIVO', 'RESERVADO', 'CONFIDENCIAL', 'SECRETO']),
priority: z.enum(['NORMAL', 'URGENTE', 'URGENTISSIMO']),
sender: z.object({
re: z.string().min(1, 'RE é obrigatório'),
name: z.string().min(1, 'Nome é obrigatório'),
rank: z.string().min(1, 'Posto/Graduação é obrigatório'),
role: z.string().min(1, 'Função é obrigatória'),
unit: z.string().min(1, 'Organização Militar é obrigatória'),
phone: z.string().optional(),
email: z.string().email('Email inválido').optional(),
}),
recipient: z.object({
name: z.string().min(1, 'Nome é obrigatório'),
rank: z.string().min(1, 'Posto/Graduação é obrigatório'),
role: z.string().min(1, 'Função é obrigatória'),
unit: z.string().min(1, 'Organização Militar é obrigatória'),
}),
subject: z.string().min(1, 'Assunto é obrigatório'),
references: z.array(z.object({
type: z.string(),
number: z.string(),
date: z.string(),
origin: z.string(),
})).optional(),
attachments: z.array(z.object({
description: z.string(),
pages: z.number(),
})).optional(),
content: z.string().min(1, 'Conteúdo é obrigatório'),
signers: z.array(z.object({
name: z.string().min(1, 'Nome é obrigatório'),
rank: z.string().min(1, 'Posto/Graduação é obrigatório'),
role: z.string().min(1, 'Função é obrigatória'),
})).min(1, 'Pelo menos um assinante é necessário'),
distribution: z.array(z.string()).optional(),
accessLevel: z.number().min(1).max(5),
version: z.number().default(1),
});
type DocumentFormData = z.infer;
interface DocumentFormProps {
onSubmit: (data: DocumentFormData) => void;
}
export function DocumentForm({ onSubmit }: DocumentFormProps) {
const { register, handleSubmit, formState: { errors }, watch, setValue } = useForm({
resolver: zodResolver(documentSchema),
defaultValues: {
references: [{ type: '', number: '', date: '', origin: '' }],
attachments: [{ description: '', pages: 0 }],
signers: [{ name: '', rank: '', role: '' }],
distribution: [''],
version: 1,
classification: 'OSTENSIVO',
priority: 'NORMAL',
}
});
const documentType = watch('documentType');
const template = MILITARY_TEMPLATES[documentType];
const handleDocumentTypeChange = (e: React.ChangeEvent) => {
const newType = e.target.value;
setValue('documentType', newType as any);
if (MILITARY_TEMPLATES[newType]?.contentTemplate) {
setValue('content', MILITARY_TEMPLATES[newType].contentTemplate || '');
}
};
return (
{/* Cabeçalho do Documento */}
Tipo de Documento
<select
{...register('documentType')}
onChange={handleDocumentTypeChange}
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500"
>
{Object.keys(MILITARY_TEMPLATES).map((type) => (
{type}
))}
{errors.documentType && (
{errors.documentType.message}
)}
);
}
Beta Was this translation helpful? Give feedback.
All reactions