-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add changes history to tower page
- Loading branch information
Showing
15 changed files
with
221 additions
and
70 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
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,89 @@ | ||
import { getChangesByTower } from "@/actions/changes/change.get"; | ||
import { getUser } from "@/actions/members/members.action"; | ||
import ApprovedIcon from "@/components/tower/tiles/changesHistory/ApprovedIcon"; | ||
import NewIcon from "@/components/tower/tiles/changesHistory/NewIcon"; | ||
import RejectedIcon from "@/components/tower/tiles/changesHistory/RejectedIcon"; | ||
import { ChangeState } from "@/types/Change"; | ||
import { Tower } from "@/typings"; | ||
import { cn } from "@/utils/cn"; | ||
import { formatDate } from "@/utils/date"; | ||
import { editableParameters } from "@/utils/editableParameters"; | ||
import { formatParameterValue } from "@/utils/formatValue"; | ||
|
||
const ChangesHistory = async ({ tower }: { tower: Tower }) => { | ||
const towerChanges = await getChangesByTower(tower.id, "", 50); //todo? implement pagination | ||
const uniqueUserIDs = [...new Set(towerChanges.map((change) => change.user_id))]; | ||
const users = await Promise.all(uniqueUserIDs.map((id) => getUser(id))); | ||
//todo add different types of changes (opening hours, admission...) | ||
if (towerChanges.length === 0) return null; | ||
return ( | ||
<div className="card shadow-xl w-full mb-5"> | ||
<div className="card-body gap-0"> | ||
<h2 className="card-title text-base sm:text-lg md:text-xl text-nowrap">Historie změn</h2> | ||
<div className="overflow-x-auto flex flex-col gap-1"> | ||
{towerChanges.map((change, idx) => { | ||
const parameter = editableParameters.find((param) => param.name === change.field); | ||
const user = users.find((user) => user.id === change.user_id); | ||
const isApproved = change.state === ChangeState.Approved; | ||
const isRejected = change.state === ChangeState.Rejected; | ||
const isNew = change.state === ChangeState.New; | ||
return ( | ||
<div | ||
key={change.id} | ||
className={cn("flex gap-1", { | ||
"mt-7": idx === 0, | ||
})} | ||
> | ||
<time className="text-gray-400 mr-1 text-nowrap">{formatDate({ date: change.created, long: false })}</time> | ||
<div className="mx-1"> | ||
{isApproved ? <ApprovedIcon /> : null} | ||
{isNew ? <NewIcon /> : null} | ||
{isRejected ? <RejectedIcon /> : null} | ||
</div> | ||
<div className="text-nowrap">{`${user.name} ${isApproved ? "změnil/a parametr" : "navrhl/a změnu parametru"}`}</div> | ||
<span className="text-nowrap"> | ||
<span className="font-bold">{parameter.label}</span>. | ||
</span> | ||
<span className="flex gap-2 ml-2 text-nowrap"> | ||
<span className={"text-neutral-500"}> | ||
{"[ "} | ||
<span className={cn({ "line-through": isApproved })}> | ||
{formatParameterValue(change.old_value, parameter.type)} | ||
</span> | ||
</span> | ||
<svg | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="currentColor" | ||
strokeWidth="2" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
className="text-neutral-500" | ||
> | ||
<path d="M18 8L22 12L18 16" /> | ||
<path d="M2 12H22" /> | ||
</svg> | ||
<div> | ||
<span | ||
className={cn("text-neutral-500", { | ||
"text-success font-bold": isApproved, | ||
"line-through": isRejected, | ||
})} | ||
> | ||
{formatParameterValue(change.new_value, parameter.type)} | ||
</span> | ||
{" ]"} | ||
</div> | ||
</span> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ChangesHistory; |
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,23 @@ | ||
const ApprovedIcon = () => { | ||
return ( | ||
<div className="tooltip" data-tip="Schváleno"> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="currentColor" | ||
strokeWidth="2" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
className="text-success" | ||
> | ||
<circle cx="12" cy="12" r="10" /> | ||
<path d="m9 12 2 2 4-4" /> | ||
</svg> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ApprovedIcon; |
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,24 @@ | ||
const NewIcon = () => { | ||
return ( | ||
<div className="tooltip" data-tip="Zatím nerozhodnuto"> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="currentColor" | ||
strokeWidth="2" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
className="text-info" | ||
> | ||
<circle cx="12" cy="12" r="10" /> | ||
<path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3" /> | ||
<path d="M12 17h.01" /> | ||
</svg> | ||
</div> | ||
); | ||
}; | ||
|
||
export default NewIcon; |
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,24 @@ | ||
const RejectedIcon = () => { | ||
return ( | ||
<div className="tooltip" data-tip="Zamítnuto"> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="currentColor" | ||
strokeWidth="2" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
className="text-error" | ||
> | ||
<circle cx="12" cy="12" r="10" /> | ||
<path d="m15 9-6 6" /> | ||
<path d="m9 9 6 6" /> | ||
</svg> | ||
</div> | ||
); | ||
}; | ||
|
||
export default RejectedIcon; |
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
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
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.