Commit 65c29f25 authored by William Schneider's avatar William Schneider
Browse files

finished task US15

parent d0cd6c72
Showing with 87 additions and 11 deletions
+87 -11
......@@ -19,23 +19,74 @@ import {
completeTask,
leaveTask,
} from "../../services/taskService";
import { accept, deny } from "../../services/userService";
import { getLoggedUserFromLocalStorage } from "../../utils/utils";
import Button from "../Button";
import EvaluationModal from "../EvaluationModal";
export interface RegistrationCardProps {
id?: string;
name?: string;
phone?: string;
email?: string;
image?: string;
findUsers: () => void;
}
const RegistrationCard = ({
id = "id",
name = "nome de empresa",
phone = "telefone",
email = "email",
image = "uma imagem",
findUsers,
}: RegistrationCardProps) => {
const [loading, setLoading] = useState(false);
const toast = useToast();
const showToastMessage = (
title: string,
status: "info" | "warning" | "success" | "error" | undefined,
position: ToastPositionWithLogical | undefined
) => {
toast({
title,
status,
position,
isClosable: true,
});
};
const acceptUser = async () => {
setLoading(true);
try {
await accept(id);
findUsers();
showToastMessage(
"Solicitacao aceita com sucesso!",
"success",
"top-right"
);
} catch (e: any) {
showToastMessage(e, "error", "top-right");
}
setLoading(false);
};
const denyUser = async () => {
setLoading(true);
try {
await deny(id);
findUsers();
showToastMessage(
"Solicitacao negada com sucesso!",
"success",
"top-right"
);
} catch (e: any) {
showToastMessage(e, "error", "top-right");
}
setLoading(false);
};
return (
<Flex
w="100%"
......@@ -82,21 +133,23 @@ const RegistrationCard = ({
theme="quaternary"
width="140px"
height="30px"
onClick={denyUser}
isLoading={loading}
margin="0px 10px 0px 10px"
fontSize="14px"
>
{" "}
Negar{" "}
Negar
</Button>
<Button
theme="secondary"
width="140px"
height="30px"
onClick={acceptUser}
isLoading={loading}
margin="0px 10px 0px 10px"
fontSize="14px"
>
{" "}
Aceitar{" "}
Aceitar
</Button>
</HStack>
</Flex>
......
......@@ -12,12 +12,11 @@ const RegistrationRequest = (): React.ReactElement => {
const [usersInactiveEntities, setUsersInactiveEntities] = useState<User[]>(
[]
);
const getUsersEntities = async () => {
const entities = await getUsersInactiveEntities();
setUsersInactiveEntities(entities);
};
useEffect(() => {
const getUsersEntities = async () => {
const entities = await getUsersInactiveEntities();
setUsersInactiveEntities(entities);
console.log(entities);
};
getUsersEntities();
}, []);
......@@ -47,13 +46,15 @@ const RegistrationRequest = (): React.ReactElement => {
</div>
<Box id="cards-collection" width="100%" alignContent="end">
<Box id="cards-collection2" width="90%" marginLeft="10%">
{usersInactiveEntities.map((entity) => (
<Box id="card" marginTop="20px">
{usersInactiveEntities.map((entity, key) => (
<Box key={key} marginTop="20px">
<RegistrationCard
id={entity.id}
name={entity.name}
email={entity.email}
image={entity.image}
phone={entity.phone}
findUsers={getUsersEntities}
/>
</Box>
))}
......
......@@ -26,3 +26,25 @@ export async function getUsersInactiveEntities(): Promise<User[]> {
return response.data;
}
export async function accept(userId: string): Promise<any> {
let response = null;
await api
.put(`${serviceName}/admin/accept/${userId}`)
.then((data) => (response = data))
.catch((error) => {
throw error;
});
return response;
}
export async function deny(userId: string): Promise<any> {
let response = null;
await api
.put(`${serviceName}/admin/deny/${userId}`)
.then((data) => (response = data))
.catch((error) => {
throw error;
});
return response;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment