-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0308ab2
commit 386286b
Showing
8 changed files
with
280 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import { useMemo } from "react" | ||
import { | ||
Badge, | ||
Box, | ||
HStack, | ||
Skeleton, | ||
Spacer, | ||
Tag, | ||
Text | ||
} from "@chakra-ui/react" | ||
|
||
import { EditButton } from "@components/ActionButtons/EditButton" | ||
import { Item } from "@components/ListItem" | ||
import { ChamadoPriority, priorityColorMap } from "@constants/Chamados" | ||
import { useRequest } from "@hooks/useRequest" | ||
import { getCityById } from "@services/Cidades" | ||
import { getWorkstationById } from "@services/Workstation" | ||
import { formatDate } from "@utils/formatDate" | ||
|
||
interface ChamadoItemProps { | ||
chamado: Chamado | ||
handleEdit: (chamado: Chamado) => void | ||
} | ||
|
||
export const ChamadoItem = ({ chamado, handleEdit }: ChamadoItemProps) => { | ||
const isEvent = useMemo( | ||
() => chamado?.problems?.some((item) => item?.is_event), | ||
[chamado?.problems] | ||
) | ||
|
||
const { data: city, isLoading: isLoadingCity } = useRequest<City>( | ||
getCityById(chamado?.city_id), | ||
{ | ||
revalidateIfStale: false | ||
} | ||
) | ||
|
||
const { data: workstation, isLoading: isLoadingWorkstation } = | ||
useRequest<Workstation>(getWorkstationById(chamado?.workstation_id), { | ||
revalidateIfStale: false | ||
}) | ||
|
||
return ( | ||
<Box> | ||
<HStack spacing={2}> | ||
{chamado.problems.map((problem, index) => ( | ||
<Badge | ||
colorScheme={priorityColorMap(problem.priority)} | ||
variant={ | ||
{ | ||
low: "outline", | ||
normal: "outline", | ||
high: "subtle", | ||
urgent: "solid" | ||
}[problem.priority] | ||
} | ||
key={index} | ||
> | ||
{ChamadoPriority[problem.priority]} | ||
</Badge> | ||
))} | ||
<Spacer /> | ||
{isEvent && ( | ||
<Text> | ||
Agendado para {formatDate(new Date())} as{" "} | ||
{formatDate(new Date(), "time")} | ||
</Text> | ||
)} | ||
</HStack> | ||
<Item | ||
title={ | ||
<> | ||
<HStack spacing={6}> | ||
<Box> | ||
<Text fontSize="sm" fontWeight="light" color="GrayText"> | ||
Solicitante | ||
</Text> | ||
<Text noOfLines={1}>{chamado?.applicant_name}</Text> | ||
</Box> | ||
<Box> | ||
<Text fontSize="sm" fontWeight="light" color="GrayText"> | ||
Posto de Trabalho | ||
</Text> | ||
<Skeleton isLoaded={!isLoadingWorkstation}> | ||
<Text noOfLines={1}>{workstation?.data?.name}</Text> | ||
</Skeleton> | ||
</Box> | ||
<Box> | ||
<Text fontSize="sm" fontWeight="light" color="GrayText"> | ||
Local | ||
</Text> | ||
<Skeleton isLoaded={!isLoadingCity}> | ||
<Text noOfLines={1}>{city?.data?.name}</Text> | ||
</Skeleton> | ||
</Box> | ||
<Box> | ||
<Text fontSize="sm" fontWeight="light" color="GrayText"> | ||
Atendente | ||
</Text> | ||
<Text noOfLines={1}>{chamado?.attendant_name}</Text> | ||
</Box> | ||
<Box> | ||
<Text fontSize="sm" fontWeight="light" color="GrayText"> | ||
Data / Hora | ||
</Text> | ||
<Box textAlign="center" fontWeight="medium"> | ||
<Text> | ||
{formatDate(chamado?.created_at, "date")}{" "} | ||
{formatDate(chamado?.created_at, "time")} | ||
</Text> | ||
</Box> | ||
</Box> | ||
</HStack> | ||
</> | ||
} | ||
description={ | ||
<Box> | ||
<HStack gap={4} mt={2} flexWrap="wrap"> | ||
{chamado?.problems.map((problem) => ( | ||
<HStack align="start" spacing={1} key={problem?.problem_id}> | ||
<Tag variant="subtle" colorScheme="gray"> | ||
{problem?.category?.name} | ||
</Tag> | ||
<Tag variant="subtle" colorScheme="purple"> | ||
{problem?.problem?.name} | ||
</Tag> | ||
</HStack> | ||
))} | ||
</HStack> | ||
</Box> | ||
} | ||
> | ||
<Item.Actions item={chamado}> | ||
<EditButton | ||
onClick={handleEdit} | ||
label={isEvent ? "Evento" : "Chamado"} | ||
/> | ||
</Item.Actions> | ||
</Item> | ||
</Box> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { useCallback, useMemo } from "react" | ||
|
||
import { ChamadoFormWrapper } from "@components/Forms/ChamadoForm/ChamadoFormWrapper" | ||
import { | ||
chamadoToFormValues, | ||
formValuesToPayload | ||
} from "@components/Forms/ChamadoForm/helpers" | ||
import { Modal } from "@components/Modal/Modal" | ||
import { updateChamado } from "@services/Chamados" | ||
import { request } from "@services/request" | ||
|
||
interface ChamadoModalProps { | ||
chamado?: Chamado | undefined | ||
onEdit: (result: Result<ApiResponse<Chamado>>) => void | ||
isOpen: boolean | ||
onClose: () => void | ||
} | ||
|
||
export const ChamadoModal = ({ | ||
chamado, | ||
onEdit, | ||
isOpen, | ||
onClose | ||
}: ChamadoModalProps) => { | ||
const isEvent = useMemo( | ||
() => chamado?.problems?.some((item) => item?.is_event), | ||
[chamado?.problems] | ||
) | ||
|
||
const onSubmit = useCallback( | ||
async (data: ChamadoFormValues) => { | ||
if (!chamado?.id) return | ||
|
||
const payload = formValuesToPayload(data) | ||
console.log("payload", payload) | ||
|
||
const response = await request<Chamado>( | ||
updateChamado(chamado?.id)(payload) | ||
) | ||
|
||
onEdit?.(response) | ||
onClose() | ||
|
||
if (response.type === "error") { | ||
// Let hook form know that submit was not successful | ||
return Promise.reject(response.error.message) | ||
} | ||
}, | ||
[chamado?.id, onClose, onEdit] | ||
) | ||
|
||
return ( | ||
<Modal | ||
title={`Editar ${isEvent ? "Evento" : "Chamado"}`} | ||
isOpen={isOpen} | ||
onClose={onClose} | ||
size="6xl" | ||
> | ||
<ChamadoFormWrapper | ||
defaultValues={chamado && chamadoToFormValues(chamado)} | ||
onSubmit={onSubmit} | ||
/> | ||
</Modal> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.