Skip to content

Commit

Permalink
Merge pull request #33 from ipti/feature/user
Browse files Browse the repository at this point in the history
fix: create registration
  • Loading branch information
jonnypaulino authored Jul 19, 2024
2 parents 7e275fd + d85f938 commit 1e5acaf
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/Context/Beneficiaries/BeneficiaresCreate/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const BeneficiariesCreateState = () => {
const [classrooms, setClassrooms] = useState<any>();
const props = ControllerPreRegistration()



useEffect(() => {
if (classroomsFetch) {
Expand All @@ -29,7 +30,7 @@ export const BeneficiariesCreateState = () => {
const CreateRegister = (values: any) => {
const data = new Date(values?.birthday);
const dataFormatada = data?.toISOString()?.split('T')[0];
props.requestRegistrationMutation.mutate({ ...values, cpf: values.cpf.replace(/[^a-zA-Z0-9]/g, ''), responsable_telephone: values.responsable_telephone.replace(/[^a-zA-Z0-9]/g, ''), birthday: dataFormatada, responsable_cpf: values?.responsable_cpf?.replace(/[^a-zA-Z0-9]/g, '') })
props.requestRegistrationMutation.mutate({ ...values, cpf: values.cpf.replace(/[^a-zA-Z0-9]/g, ''),kinship: values.kinship === "" ? "NAO_DEFINIDO" : values.kinship, responsable_telephone: values.responsable_telephone.replace(/[^a-zA-Z0-9]/g, ''), birthday: dataFormatada, responsable_cpf: values?.responsable_cpf?.replace(/[^a-zA-Z0-9]/g, '') })
}


Expand Down
1 change: 1 addition & 0 deletions src/Context/Beneficiaries/BeneficiaresEdit/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const BeneficiariesEditState = () => {
/[^a-zA-Z0-9]/g,
""
),
kinship: data.kinship === "" ? "NAO_DEFINIDO" : data.kinship,
responsable_cpf: data?.responsable_cpf?.replace(/[^a-zA-Z0-9]/g, ""),
},
id: id,
Expand Down
8 changes: 6 additions & 2 deletions src/Context/Beneficiaries/BeneficiariesList/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const BeneficiariesListProvider = ({
cpfFilter,
nameFilter,
allFilter,
setallFilter
setallFilter,
setTsId,
tsId
} = BeneficiariesListState();

return (
Expand All @@ -41,7 +43,9 @@ const BeneficiariesListProvider = ({
cpfFilter,
nameFilter,
allFilter,
setallFilter
setallFilter,
setTsId,
tsId
}}
>
{children}
Expand Down
7 changes: 5 additions & 2 deletions src/Context/Beneficiaries/BeneficiariesList/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const BeneficiariesListState = () => {
const [page, setPage] = useState(0);
const [limite, setLimite] = useState(10);
const [nameFilter, setnameFilter] = useState<string | undefined>();
const [tsId, setTsId] = useState<number | undefined>()

const [cpfFilter, setcpfFilter] = useState<string | undefined>();
const [allFilter, setallFilter] = useState<string | undefined>("");
Expand All @@ -18,7 +19,8 @@ export const BeneficiariesListState = () => {
page: Math.floor(page / 10 + 1),
name: nameFilter !== "" ? nameFilter : undefined,
cpf: cpfFilter !== "" ? cpfFilter?.replace(/[^a-zA-Z0-9]/g, '') : undefined,
allFilter: allFilter !== "" ? allFilter : undefined
allFilter: allFilter !== "" ? allFilter : undefined,
idTs: tsId?.toString(),
});

const handleFilter = (values: { name: string; cpf: string }) => {
Expand Down Expand Up @@ -50,6 +52,7 @@ export const BeneficiariesListState = () => {
nameFilter,
cpfFilter,
allFilter,
setallFilter
setallFilter,
tsId, setTsId
};
};
2 changes: 2 additions & 0 deletions src/Context/Beneficiaries/BeneficiariesList/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export interface BeneficiariesListType {
nameFilter: string | undefined
cpfFilter: string | undefined
allFilter: string | undefined
tsId: number | undefined
setTsId: Dispatch<SetStateAction<number | undefined>>
setallFilter: Dispatch<SetStateAction<string | undefined>>
handleFilter: (values: {
name: string;
Expand Down
1 change: 1 addition & 0 deletions src/Context/Classroom/Registration/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const RegistrationClassroomState = () => {
/[^a-zA-Z0-9]/g,
""
),
kinship: data.kinship === "" ? "NAO_DEFINIDO" : data.kinship,
responsable_cpf: data?.responsable_cpf?.replace(/[^a-zA-Z0-9]/g, ""),
},
id: id,
Expand Down
2 changes: 1 addition & 1 deletion src/Context/Classroom/Registration/type.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface UpdateRegister
status: {id: string, name: string} | undefined;
registration_classroom_id?: number
deficiency_description: any
kinship: string | undefined
kinship: string | undefined | null
}
export interface RegistrationType {
id: number
Expand Down
2 changes: 1 addition & 1 deletion src/Context/Register/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const RegisterState = () => {
const data = new Date(dataValues?.birthday);
const dataFormatada = data?.toISOString()?.split('T')[0];

props.requestPreRegistrationMutation.mutate({ ...dataValues, cpf: dataValues.cpf.replace(/[^a-zA-Z0-9]/g, ''), responsable_telephone: dataValues.responsable_telephone.replace(/[^a-zA-Z0-9]/g, ''), birthday: dataFormatada, responsable_cpf: dataValues?.responsable_cpf?.replace(/[^a-zA-Z0-9]/g, '') })
props.requestPreRegistrationMutation.mutate({ ...dataValues, cpf: dataValues.cpf.replace(/[^a-zA-Z0-9]/g, ''),kinship: dataValues.kinship === "" ? "NAO_DEFINIDO" : dataValues.kinship, responsable_telephone: dataValues.responsable_telephone.replace(/[^a-zA-Z0-9]/g, ''), birthday: dataFormatada, responsable_cpf: dataValues?.responsable_cpf?.replace(/[^a-zA-Z0-9]/g, '') })
}

const initialState: Registration = {
Expand Down
2 changes: 1 addition & 1 deletion src/Context/Register/type.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface Registration {
responsable_name?: string;
responsable_cpf?: string;
responsable_telephone?: string;
kinship?: string;
kinship?: string | null;
zone: number | null;
}

Expand Down
12 changes: 5 additions & 7 deletions src/Controller/controllerGlobal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,14 @@ export const ROLE = {
export const kinship = [
{ id: "PAI", name: 'Pai' },
{ id: "MAE", name: 'Mãe' },
{ id: "CONJUGE", name: 'Cônjuge' },
{ id: "PRIMO_A", name: 'Primo(a)' },
{ id: "TIO_A", name: 'Tio(a)' },
{ id: "FILHO_A", name: 'Filho(a)' },
{ id: "ENTEADO_A", name: 'Enteado(a)' },
{ id: "NETO_A", name: 'Neto(a)' },
{ id: "SOGRO_A", name: 'Sogro(a)' },
{ id: "IRMAO_A", name: 'Irmão(a)' },
{ id: "GENRO", name: 'Genro' },
{ id: "NORA", name: 'Nora' },
{ id: "OUTRO", name: 'Outro' },
{ id: "NAO_PARENTE", name: 'Não Parente' }
{ id: "NAO_PARENTE", name: 'Não Parente' },
{ id: "NAO_DEFINIDO", name: 'Não Definido' }

]

export const loadImageFileAsBase64 = (imagePath: string): Promise<string> => {
Expand Down
20 changes: 20 additions & 0 deletions src/Pages/Beneficiaries/BeneficiariesList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import {
import color from "../../../Styles/colors";
import { Padding, Row } from "../../../Styles/styles";
import ModalFilter from "./ModalFilter";
import DropdownComponent from "../../../Components/Dropdown";
import { PropsAplicationContext } from "../../../Types/types";
import { AplicationContext } from "../../../Context/Aplication/context";

const BeneficiariesList = () => {
return (
Expand All @@ -30,6 +33,7 @@ const BeneficiariesList = () => {

const BeneficiariesListPage = () => {
const props = useContext(BeneficiariesListContext) as BeneficiariesListType;
const propsAplication = useContext(AplicationContext) as PropsAplicationContext;
const history = useNavigate();

const [visible, setVisible] = useState<any>();
Expand Down Expand Up @@ -91,6 +95,22 @@ const BeneficiariesListPage = () => {
return (
<>
<ContentPage title="Beneficiários" description="Visualização dos beneficiários da tecnologia.">
<Row id="end">

{propsAplication.project
? (
<DropdownComponent
placerholder="Escolha uma tecnologia"
options={[{ name: "Todos", id: undefined }, ...propsAplication.project]}
value={props.tsId}
optionsValue="id"

onChange={(e) => {
props.setTsId(e.target.value);
}}
/>
) : null}{" "}
</Row>
<Padding padding="16px" />
<Row style={{ gap: 8 }}>
{props.nameFilter?.length! > 0 && (
Expand Down
10 changes: 6 additions & 4 deletions src/Services/Beneficiaries/query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ export const useFetchRequestAllRegistration = ({
limite,
cpf,
name,
allFilter
allFilter,
idTs
}: {
page: number;
limite: number;
name?: string;
cpf?: string;
allFilter?: string
allFilter?: string,
idTs?: string,
}) => {
return useQuery(["useRequestAllRegistration", page, limite, cpf, name, allFilter], () =>
requestAllRegistration({ limite: limite, page: page, cpf: cpf, name: name, allFilter: allFilter })
return useQuery(["useRequestAllRegistration", page, limite, cpf, name, allFilter, idTs], () =>
requestAllRegistration({ limite: limite, page: page, cpf: cpf, name: name, allFilter: allFilter, idTs: idTs })
);
};
11 changes: 7 additions & 4 deletions src/Services/Beneficiaries/request.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
import http from "../axios";
import { GetIdTs, logout } from "../localstorage";
import { logout } from "../localstorage";

export const requestAllRegistration = ({
page,
limite,
cpf,
name,
allFilter
allFilter,
idTs,
}: {
page: number;
limite: number;
name?: string,
idTs?: string,
cpf?: string,
allFilter?: string
}) => {
const nameFilter = name ? "&nameFilter=" + name : ""
const cpfFilter = cpf ? "&cpfFilter=" + cpf : ""
const allFilterRequest = allFilter ? "&allFilter=" + allFilter : ""
const idTsFilter = idTs ? "&idTs=" + idTs : ""
const allFilterRequest = allFilter ? "&allFilter=" + allFilter.replace(/[^a-zA-Z0-9 ]/g, '') : ""

let path =
"/registration-token-bff/registration-all?page=" +
page +
"&limit=" +
limite + "&idTs="+ GetIdTs() + nameFilter + cpfFilter + allFilterRequest;
limite + idTsFilter + nameFilter + cpfFilter + allFilterRequest;
return http
.get(path)
.then((response) => response.data)
Expand Down
1 change: 1 addition & 0 deletions src/Services/PreRegistration/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface CreatePreRegistration {
responsable_telephone?: string | null;
zone: number;
classroom: number;
kinship: string | undefined | null
}

export interface CreateRegistrationClassroomType {
Expand Down

0 comments on commit 1e5acaf

Please sign in to comment.