Skip to content

Commit

Permalink
fix: make fixes in incedent details
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksandrSekker authored and DmitriiMelnikOnix committed Mar 10, 2022
1 parent 9c44ce3 commit c7b6d23
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/components/IncidentDetails/data.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Temporary mock, in the future you need to replace it with an array of real respondents received from the apis
import {
HiOutlineChevronDoubleUp,
HiOutlineChevronDown,
Expand All @@ -7,6 +6,7 @@ import {
import React from "react";
import { IncidentPriority } from "../../constants/incident-priority";

// Temporary mock, in the future you need to replace it with an array of real respondents received from the apis
export const personRespondents = [
{
label: "Lindsay Walton",
Expand Down
28 changes: 19 additions & 9 deletions src/components/IncidentDetails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ export const IncidentDetails = ({
const { control, getValues, watch } = useForm({
defaultValues: {
tracking: "123456",
started: incident.created_at,
duration: incident.created_at,
created_at: incident.created_at,
chartRoomTitle: "#Slack",
chartRoom: "https://google.com.ua",
statusPageTitle: "StatusPage.io",
Expand All @@ -47,11 +46,22 @@ export const IncidentDetails = ({
}
});
watch();
const formatDate = (date, fallback = "-") => {
const getDate = date ? dayjs(date).format("DD.MM.YYYY") : fallback;
const getDuration = date ? dayjs(incident.created_at).fromNow() : fallback;
return { getDate, getDuration };
};
const DATE_FORMAT = "DD.MM.YYYY";
const formatDate = ({ date, format = DATE_FORMAT, fallback = "-" }) =>
date ? dayjs(date).format(format) : fallback;
const dateToDuration = ({ date, withoutSuffix = false, fallback = "-" }) =>
date ? dayjs(date).fromNow(withoutSuffix) : fallback;

const watchCreatedAt = watch("created_at");

const formattedCreatedAt = useMemo(
() => formatDate({ date: watchCreatedAt }),
[watchCreatedAt]
);
const formattedDuration = useMemo(
() => dateToDuration({ date: watchCreatedAt }),
[watchCreatedAt]
);
return (
<div className="px-6 pt-3.5">
<div className="flex justify-between mb-7">
Expand Down Expand Up @@ -140,15 +150,15 @@ export const IncidentDetails = ({
title="Started"
value={
<span className="text-dark-gray text-sm font-normal">
{formatDate(getValues("started")).getDate}
{formattedCreatedAt}
</span>
}
/>
<IncidentDetailsRow
title="Duration"
value={
<span className="text-dark-gray text-sm font-normal">
{formatDate(getValues("duration")).getDuration}
{formattedDuration}
</span>
}
/>
Expand Down

0 comments on commit c7b6d23

Please sign in to comment.