Skip to content

Commit

Permalink
Merge pull request #46 from ipti/feature/address
Browse files Browse the repository at this point in the history
Feature/address
  • Loading branch information
jonnypaulino authored Dec 16, 2024
2 parents 6500b18 + 6bef7f4 commit 3769744
Show file tree
Hide file tree
Showing 26 changed files with 717 additions and 64 deletions.
7 changes: 6 additions & 1 deletion src/Assets/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
padding: 0;
outline: 0;
box-sizing: border-box;
font-family: 'Quicksand', 'Poppins', sans-serif;
font-family: "Poppins Regular";
}

html,
Expand All @@ -21,6 +21,11 @@
scroll-behavior: smooth;
}


h1 {
font-family: "Poppins Regular";
text-transform: uppercase;
}

@font-face {
font-family: "Poppins Regular";
Expand Down
172 changes: 172 additions & 0 deletions src/Components/InputsAddress/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import axios from "axios";
import { useEffect, useState } from "react";
import { useFetchRequestState } from "../../Services/Address/query";
import { StateList } from "../../Services/Address/type";
import { Padding } from "../../Styles/styles";
import DropdownComponent from "../Dropdown";
import MaskInput from "../InputMask";
import TextInput from "../TextInput";


const InputAddressState = () => {

const [state, setState] = useState<StateList | undefined>();
const [stateId, setStateId] = useState<number | undefined>()


const { data: stateRequest } = useFetchRequestState()


useEffect(() => {
if (stateRequest) {
setState(stateRequest)
}
}, [stateRequest])


const dadosCep = async (value: string, setFieldValue: any) => {
if (value) {

const cep = value.replace(/[^a-zA-Z0-9 ]/g, '');

await axios.get("https://viacep.com.br/ws/" + cep + "/json/").then((data) => {
const stateCep = state?.find(props => props.acronym === data.data.uf)
const cityCep = stateCep?.city.find(props => props.name === data.data.localidade.toUpperCase())

setFieldValue("address", data.data.logradouro);
setFieldValue("neighborhood", data.data.bairro);
setFieldValue("complement", data.data.complemento);
setFieldValue("state", stateCep?.id)
setFieldValue("city", cityCep?.id)
}).catch(
(error) => {
return error
}
)
}
}

return { dadosCep, state, setStateId, stateId }
}

const InputAddress = ({ errors, handleChange, touched, values, setFieldValue }: { values: any, handleChange: any, errors: any, touched: any, setFieldValue: any }) => {

const props = InputAddressState();

useEffect(() => {
if (values.state) {
props.setStateId(values.state)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [values.state])

return (
<div className="grid">
<div className="col-12 md:col-6">
<label>CEP </label>
<Padding />
<MaskInput
value={values.cep}
mask="99999-999"
placeholder="Cep"
onChange={(e) => {
setFieldValue("cep", e.target.value)
props.dadosCep(e.target.value!, setFieldValue)
}}
name="cep"
/>
{errors.cep && touched.cep ? (
<div style={{ color: "red", marginTop: "8px" }}>
{errors.cep}
</div>
) : null}
</div>
<div className="col-12 md:col-6">
<label>Endereço </label>
<Padding />
<TextInput
value={values.address}
placeholder="Endereço"
onChange={handleChange}
name="address"
/>
{errors.address && touched.address ? (
<div style={{ color: "red", marginTop: "8px" }}>
{errors.address}
</div>
) : null}
</div>
<div className="col-12 md:col-6">
<label>Bairro </label>
<Padding />
<TextInput
value={values.neighborhood}
placeholder="Bairro"
onChange={handleChange}
name="neighborhood"
/>
{errors.neighborhood && touched.neighborhood ? (
<div style={{ color: "red", marginTop: "8px" }}>
{errors.neighborhood}
</div>
) : null}
</div>
<div className="col-12 md:col-6">
<label>Complemento </label>
<Padding />
<TextInput
value={values.complement}
placeholder="Complemento"
onChange={handleChange}
name="complement"
/>
{errors.neighborhood && touched.neighborhood ? (
<div style={{ color: "red", marginTop: "8px" }}>
{errors.neighborhood}
</div>
) : null}
</div>
{props.state && <>
<div className="col-12 md:col-6">
<label>Estado *</label>
<Padding />
<DropdownComponent
value={values.state}
placerholder="Estado"
name="state"
optionsValue="id"
onChange={(e) => {
setFieldValue("state", e.target.value)
props.setStateId(e.target.value.id)
}}
options={props.state}
/>
{errors.state ? (
<div style={{ color: "red", marginTop: "8px" }}>
{errors.state}
</div>
) : null}
</div>
{props.stateId && <div className="col-12 md:col-6">
<label>Cidade *</label>
<Padding />
<DropdownComponent
value={values.city}
placerholder="Cidade"
name="city"
optionsValue="id"
onChange={handleChange}
options={props.state.find(item => item.id === props.stateId)?.city}
/>
{errors.city ? (
<div style={{ color: "red", marginTop: "8px" }}>
{errors.city}
</div>
) : null}
</div>}
</>}
</div>
)
}

export default InputAddress
11 changes: 9 additions & 2 deletions src/Context/Beneficiaries/BeneficiaresCreate/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,16 @@ export const BeneficiariesCreateState = () => {
zone: undefined,
project: undefined,
status: "",
classroom: 0,
classroom: undefined,
deficiency_description: "",
kinship: ""
kinship: "",
address: "",
cep: "",
neighborhood: "",
number: "",
complement: "",
state: undefined,
city: undefined
};


Expand Down
2 changes: 1 addition & 1 deletion src/Context/Beneficiaries/BeneficiaresCreate/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface BeneficiariesCreateType {
responsable_cpf: string;
responsable_telephone: string;
status: string;
classroom: number;
classroom: number | undefined;
zone: number | undefined,
project: number | undefined,
deficiency_description: string | undefined
Expand Down
4 changes: 3 additions & 1 deletion src/Context/Beneficiaries/BeneficiaresEdit/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const BeneficiariesEditProvider = ({
projectRequet,
setProject,
file,
setFile
setFile,
CreateRegisterTerm
} = BeneficiariesEditState();

return (
Expand All @@ -40,6 +41,7 @@ const BeneficiariesEditProvider = ({
project,
projectRequet,
setProject,
CreateRegisterTerm
}}
>
{children}
Expand Down
29 changes: 21 additions & 8 deletions src/Context/Beneficiaries/BeneficiaresEdit/state.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { useEffect, useState } from "react";
import { useParams } from "react-router-dom";
import {
useFetchRequestProjectList,
useFetchRequestRegistrationOne,
} from "../../../Services/PreRegistration/query";
import { Registration } from "./type";
import {
converterData,
formatarData,
getStatus,
VerifyColor,
VerifySex,
} from "../../../Controller/controllerGlobal";
import { useFetchRequestClassroom } from "../../../Services/Classroom/query";
import { ControllerUpdateRegistration } from "../../../Services/PreRegistration/controller";
import { CreateRegistrationClassroomType } from "../../../Services/PreRegistration/types";
import {
useFetchRequestProjectList,
useFetchRequestRegistrationOne,
} from "../../../Services/PreRegistration/query";
import { CreateRegistrationClassroomType, CreateRegistrationTermType } from "../../../Services/PreRegistration/types";
import { UpdateRegister } from "../../Classroom/Registration/type";
import { useFetchRequestClassroom } from "../../../Services/Classroom/query";
import { Registration } from "./type";

export const BeneficiariesEditState = () => {
const [project, setProject] = useState<any | undefined>();
Expand All @@ -30,6 +30,7 @@ export const BeneficiariesEditState = () => {
requestDeleteRegistrationClassroomMutation,
requestPreRegistrationMutation,
requestCHangeAvatarRegistrationMutation,
requestRegisterTermMutation
} = ControllerUpdateRegistration();
const { data: registrationsRequests, isLoading } =
useFetchRequestRegistrationOne(id!);
Expand All @@ -50,7 +51,6 @@ export const BeneficiariesEditState = () => {
}, [registrationsRequests]);

const date = new Date(registrations?.birthday!);

const initialValue = {
name: registrations?.name,
sex: VerifySex(registrations?.sex!),
Expand All @@ -68,12 +68,24 @@ export const BeneficiariesEditState = () => {
status: getStatus(registrations?.status!),
deficiency_description: registrations?.deficiency_description,
kinship: registrations?.kinship,
address: registrations?.address ?? "",
cep: registrations?.cep ?? "",
neighborhood: registrations?.neighborhood ?? "",
number: registrations?.number ?? "",
complement: registrations?.complement ?? "",
state: registrations?.state_fk ?? "",
city: registrations?.city_fk ?? ""
};

const CreateRegisterClassroom = (data: CreateRegistrationClassroomType) => {
requestRegistrationClassroomMutation.mutate(data);
};

const CreateRegisterTerm = (data: CreateRegistrationTermType) => {
requestRegisterTermMutation.mutate({data: data});
};


const DeleteRegistration = (id: number) => {
requestDeleteRegistrationClassroomMutation.mutate(id);
};
Expand Down Expand Up @@ -114,5 +126,6 @@ export const BeneficiariesEditState = () => {
classrooms,
file,
setFile,
CreateRegisterTerm
};
};
46 changes: 28 additions & 18 deletions src/Context/Beneficiaries/BeneficiaresEdit/type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Dispatch, SetStateAction } from "react";
import { CreateRegistrationClassroomType } from "../../../Services/PreRegistration/types";
import { CreateRegistrationClassroomType, CreateRegistrationTermType } from "../../../Services/PreRegistration/types";
import { UpdateRegister } from "../../Classroom/Registration/type";

export interface BeneficiariesEditType {
Expand All @@ -15,27 +15,37 @@ export interface BeneficiariesEditType {
classrooms: any
file: any | undefined
setFile: Dispatch<SetStateAction<any | undefined>>
CreateRegisterTerm: (data: CreateRegistrationTermType) => void
}

export interface Registration {
id: number;
name: string;
birthday: string;
cpf: string;
sex: number;
avatar_url: string | null
color_race: number;
deficiency: boolean;
deficiency_description: string;
responsable_name: any;
responsable_cpf: any;
responsable_telephone: string;
zone: number;
status: string;
createdAt: string;
updatedAt: string;
register_classroom: RegisterClassroom[];
id: number
avatar_url: string
name: string
birthday: string
cpf: string
sex: number
color_race: number
deficiency: boolean
deficiency_description: string
responsable_name: string
responsable_cpf: string
responsable_telephone: string
zone: number
kinship: string
kinship_description: any
status: string
createdAt: string
updatedAt: string
cep: string
address: any
number: any
complement: string
neighborhood: string
city_fk: number
state_fk: number
register_classroom: RegisterClassroom[]
register_term: any
}

export interface RegisterClassroom {
Expand Down
1 change: 1 addition & 0 deletions src/Context/Classroom/Registration/type.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ export interface Registration {
createdAt: string
updatedAt: string
kinship: string
register_term?: any
}
2 changes: 2 additions & 0 deletions src/Context/Register/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export const RegisterState = () => {
responsable_cpf: "",
responsable_name: "",
responsable_telephone: "",
city: null,
state: null
};

return {
Expand Down
Loading

0 comments on commit 3769744

Please sign in to comment.