diff --git a/src/app/page.tsx b/src/app/page.tsx
index 82fa791..2bbf58d 100644
--- a/src/app/page.tsx
+++ b/src/app/page.tsx
@@ -1,9 +1,9 @@
-import JobForm from '../components/molecules/JobForm/index'
+import JobForm from "../components/molecules/JobForm/index";
export default function Home() {
return (
<>
-
+
>
- )
+ );
}
diff --git a/src/components/atoms/InputForm/index.tsx b/src/components/atoms/InputForm/index.tsx
index 74443ae..83ed118 100644
--- a/src/components/atoms/InputForm/index.tsx
+++ b/src/components/atoms/InputForm/index.tsx
@@ -1,69 +1,84 @@
-import { Label } from './label';
-import { ContainerInput , Field } from './style'
-import React, { useState } from 'react'
+import { useField } from "formik";
+import { Label } from "./label";
+import { ContainerInput, Field, StyledError } from "./style";
interface InputFormProps {
- id: string;
- name: string;
- type?: string;
- placeholder?: string;
- label: string
- width: string
- height?: string
- as?: string
- options?: Array
+ id: string;
+ name: string;
+ type?: string;
+ placeholder?: string;
+ label: string;
+ width: string;
+ height?: string;
+ as?: string;
+ options?: Array;
+ minDate?: string;
+ maxDate?: string;
+ callback?: (value: string) => void;
}
export default function InputForm({
- id,
- name,
- type,
- placeholder,
- label,
- width,
- height,
- as,
- options,
-} : InputFormProps) {
- const [selectedValue, setSelectedValue] = useState('');
+ id,
+ name,
+ type,
+ placeholder,
+ label,
+ width,
+ height,
+ as,
+ options,
+ minDate,
+ maxDate,
+ callback,
+}: InputFormProps) {
+ const [field] = useField(name);
- const handleSelectChange = (event: any) => {
- setSelectedValue(event.target.value);
- console.log(event.target.value);
- };
+ const handleSelectChange = (event: any) => {
+ if (callback) {
+ callback(event.target.value);
+ }
- return (
-
-
- {as === 'select' ?
-
- {options?.map((op, index) => (
-
- ))}
-
- :
-
- }
-
- );
-}
\ No newline at end of file
+ field.onChange(event);
+ };
+
+ return (
+
+
+ {as === "select" ? (
+ <>
+
+ {options?.map((op, index) => (
+
+ ))}
+
+
+ >
+ ) : (
+ <>
+
+
+
+ >
+ )}
+
+ );
+}
diff --git a/src/components/atoms/InputForm/style.ts b/src/components/atoms/InputForm/style.ts
index b270502..317100d 100644
--- a/src/components/atoms/InputForm/style.ts
+++ b/src/components/atoms/InputForm/style.ts
@@ -1,4 +1,4 @@
-import { Field as FieldComponent } from "formik";
+import { ErrorMessage, Field as FieldComponent } from "formik";
import styled from "styled-components";
export const ContainerInput = styled.div`
@@ -33,7 +33,13 @@ export const StyledLabel = styled.label`
height: 15px;
`;
+export const StyledError = styled(ErrorMessage)`
+ margin-left: 5px;
+ height: 15px;
+ color: #ff0000;
+ font-size: 12px;
+`;
export const StyledLabelError = styled(StyledLabel)`
margin-left: 5px;
height: 15px;
-`;
\ No newline at end of file
+`;
diff --git a/src/components/molecules/JobForm/index.tsx b/src/components/molecules/JobForm/index.tsx
index 1173bd6..41eaf2b 100644
--- a/src/components/molecules/JobForm/index.tsx
+++ b/src/components/molecules/JobForm/index.tsx
@@ -1,6 +1,6 @@
"use client";
-import { Formik, Form } from "formik";
+import { Formik, Form, FormikProps } from "formik";
import InputForm from "../../atoms/InputForm/index";
import {
ContainerForm,
@@ -13,10 +13,11 @@ import {
ContainerModalButtons,
} from "./style";
import Modal from "react-modal";
-import { useState } from "react";
+import { useState, useRef } from "react";
import * as Yup from "yup";
-export default function JobPostingForm() {
+export default function JobForm() {
+ const formRef = useRef>(null);
const [modalIsOpen, setModalIsOpen] = useState(false);
function handleOpenModal() {
@@ -28,7 +29,43 @@ export default function JobPostingForm() {
}
function handleSubmit() {
- alert("Vaga cadastrada com sucesso!");
+ formRef.current?.resetForm();
+ formRef.current?.submitForm();
+ }
+
+ function callbackCanalDivulgacao(value: string) {
+ console.log(value);
+ if (value === "Devit-se") {
+ document.getElementById("form_empresa")!.style.display = "block";
+ } else {
+ document.getElementById("form_empresa")!.style.display = "none";
+ }
+ }
+ function callbackFormatoVaga(value: string) {
+ console.log(value);
+ if (value === "Home Office") {
+ document.getElementById("form_empresa")!.style.display = "none";
+ document.getElementById("semana")!.style.display = "none";
+ } else {
+ document.getElementById("form_empresa")!.style.display = "block";
+ document.getElementById("semana")!.style.display = "block";
+ }
+ }
+ function callbackOutros(value: string) {
+ console.log(value);
+ if (value === "Outros") {
+ document.getElementById("outro_contrato")!.style.display = "block";
+ } else {
+ document.getElementById("outro_contrato")!.style.display = "none";
+ }
+ }
+ function callbackSetor(value: string) {
+ console.log(value);
+ if (value === "Outros") {
+ document.getElementById("outro_setor")!.style.display = "block";
+ } else {
+ document.getElementById("outro_setor")!.style.display = "none";
+ }
}
const customStyles = {
@@ -78,9 +115,19 @@ export default function JobPostingForm() {
};
const selectOptions = {
- titulo: ["Titulo", "UX Designer", "UI Designer", "Product Designer", "Dev. Front-End", "Dev. Back-End", "Full Stack", "Agilista","Quality Assurance"],
+ titulo: [
+ "Titulo",
+ "UX Designer",
+ "UI Designer",
+ "Product Designer",
+ "Dev. Front-End",
+ "Dev. Back-End",
+ "Full Stack",
+ "Agilista",
+ "Quality Assurance",
+ ],
nivel: ["Nível", "Júnior", "Pleno", "Senior"],
- formatoVaga: ["Formato da vaga", "Presencial", "Remoto", "Híbrido"],
+ formatoVaga: ["Formato da vaga", "Presencial", "Home Office", "Híbrido"],
canalDivulgacao: [
"Canal de Divulgação",
"Devit-se",
@@ -111,6 +158,23 @@ export default function JobPostingForm() {
nota: ["Pontuação", "Nível 1", "Nível 2", "Nível 3", "Nível 4", "Nível 5"],
};
+ const validationSchema = Yup.object().shape({
+ titulo: Yup.string().required("Campo obrigatório"),
+ nivel: Yup.string().required("Campo obrigatório"),
+ formatoVaga: Yup.string().required("Campo obrigatório"),
+ canal: Yup.string().required("Campo obrigatório"),
+ link: Yup.string().required("Campo obrigatório"),
+ empresa: Yup.string().required("Campo obrigatório"),
+ status: Yup.string().required("Campo obrigatório"),
+ data: Yup.string().required("Campo obrigatório"),
+ data2: Yup.string().required("Campo obrigatório"),
+ email1: Yup.string().required("").matches( /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/, "E-mail inválido"),
+ email2: Yup.string().required("").matches( /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/, "E-mail inválido"),
+ telefone1: Yup.string().required("").length(11, "Telefone inválido"),
+ telefone2: Yup.string().required("").length(11, "Telefone inválido"),
+ cnpj: Yup.string().required("").length(14, "CNPJ inválido"),
+ });
+
return (
<>
{
console.log(values);
alert(JSON.stringify(values, null, 2));
actions.setSubmitting(false);
}}
+ validationSchema={validationSchema}
>