-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Client details page #282
Merged
+813
−402
Merged
Client details page #282
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
790cceb
client list page updated
233a904
clean up
2ee1c7c
folder structure updated
f79b1d0
client details page
81b4086
client side validation
0d693a9
conflict resolved
fd027e4
ui lint fixes
f8ce3e7
lint fixes
1bf1014
pagy updated
c6333be
client updates
9fa0001
Merge branch 'develop' into client-details-page
ac690fa
ruby tests updated
09b3683
commented index_spec.rb in spec/requests/clients folder
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Empty file.
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,84 @@ | ||
import React, { useState } from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { ArrowLeft, DotsThreeVertical, Receipt, Pencil, CaretDown, Trash } from "phosphor-react"; | ||
|
||
const Header = ({ clientDetails }) => { | ||
|
||
const [isHeaderMenuVisible, setHeaderMenuVisibility] = useState<boolean>(false); | ||
const [isClientOpen, toggleClientDetails] = useState<boolean>(false); | ||
|
||
const navigate = useNavigate(); | ||
|
||
const handleClientDetails = () => { | ||
toggleClientDetails(!isClientOpen); | ||
}; | ||
|
||
const handleMenuVisibility = () => { | ||
setHeaderMenuVisibility(!isHeaderMenuVisible); | ||
}; | ||
|
||
const handleBackButtonClick = () => { | ||
navigate("/clients"); | ||
}; | ||
|
||
const menuBackground = isHeaderMenuVisible ? "bg-miru-gray-1000" : ""; | ||
return ( | ||
<div className="my-6"> | ||
<div className="flex min-w-0 items-center justify-between"> | ||
<div className="flex items-center"> | ||
<button className="button-icon__back" onClick={handleBackButtonClick}> | ||
<ArrowLeft size={20} color="#5b34ea" weight="bold" /> | ||
</button> | ||
<h2 className="text-3xl mr-6 font-extrabold text-gray-900 sm:text-4xl sm:truncate py-1"> | ||
{clientDetails.name} | ||
</h2> | ||
<button onClick={handleClientDetails}> | ||
<CaretDown size={20} weight="bold" /> | ||
</button> | ||
</div> | ||
<div className="relative h-8"> | ||
<button onClick = {handleMenuVisibility} className={`menuButton__button ${menuBackground}`}> | ||
<DotsThreeVertical size={20} color="#000000" /> | ||
</button> | ||
{ isHeaderMenuVisible && <ul className="menuButton__wrapper"> | ||
<li> | ||
<button className="menuButton__list-item"> | ||
<Receipt size={16} color="#5B34EA" weight="bold" /> | ||
<span className="ml-3">Add Client</span> | ||
</button> | ||
</li> | ||
<li> | ||
<button className="menuButton__list-item"> | ||
<Pencil size={16} color="#5b34ea" weight="bold" /> | ||
<span className="ml-3">Edit</span> | ||
</button> | ||
</li> | ||
<li> | ||
<button className="menuButton__list-item text-miru-red-400"> | ||
<Trash size={16} color="#E04646" weight="bold" /> | ||
<span className="ml-3">Delete</span> | ||
</button> | ||
</li> | ||
</ul> } | ||
</div> | ||
</div> | ||
{isClientOpen && <div className="flex ml-12 mt-4"> | ||
<div className="text-xs text-miru-dark-purple-400"> | ||
<h6 className="font-semibold">Email ID(s)</h6> | ||
<p>{clientDetails.email}</p> | ||
</div> | ||
<div className="ml-28 text-xs text-miru-dark-purple-400"> | ||
<h6 className="font-semibold">Address</h6> | ||
<p>--</p> | ||
</div> | ||
<div className="ml-28 text-xs text-miru-dark-purple-400"> | ||
<h6 className="font-semibold">Phone number</h6> | ||
<p>--</p> | ||
</div> | ||
</div> | ||
} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Header; |
170 changes: 170 additions & 0 deletions
170
app/javascript/src/components/Clients/Details/index.tsx
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,170 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { useParams } from "react-router-dom"; | ||
import { ToastContainer } from "react-toastify"; | ||
import { setAuthHeaders, registerIntercepts } from "apis/axios"; | ||
import clients from "apis/clients"; | ||
|
||
import AmountBoxContainer from "common/AmountBox"; | ||
import ChartBar from "common/ChartBar"; | ||
import Table from "common/Table"; | ||
|
||
import Header from "./Header"; | ||
import { unmapClientDetails } from "../../../mapper/client.mapper"; | ||
import DeleteClient from "../Modals/DeleteClient"; | ||
import EditClient from "../Modals/EditClient"; | ||
|
||
const getTableData = (clients) => { | ||
if (clients) { | ||
return clients.map((client) => { | ||
const hours = client.minutes/60; | ||
return { | ||
col1: <div className="text-base text-miru-dark-purple-1000">{client.name}</div>, | ||
col2: <div className="text-base text-miru-dark-purple-1000">{client.team.map(member => <span>{member}, </span>)}</div>, | ||
col3: <div className="text-base text-miru-dark-purple-1000 text-right">{hours}</div>, | ||
rowId: client.id | ||
}; | ||
}); | ||
} | ||
return [{}]; | ||
}; | ||
|
||
const ClientList = ({ isAdminUser }) => { | ||
const [showEditDialog, setShowEditDialog] = useState<boolean>(false); | ||
const [showDeleteDialog, setShowDeleteDialog] = useState<boolean>(false); | ||
const [clientToEdit, setClientToEdit] = useState({}); | ||
const [clientToDelete, setClientToDelete] = useState({}); | ||
const [clientData, setClientData] = useState<any>(); | ||
const [totalMinutes, setTotalMinutes] = useState(null); | ||
const [clientDetails, setClientDetails] = useState<any>({}); | ||
|
||
const params = useParams(); | ||
|
||
const handleEditClick = (id) => { | ||
setShowEditDialog(true); | ||
const editSelection = clientData.find(client => client.id === id); | ||
setClientToEdit(editSelection); | ||
}; | ||
|
||
const handleDeleteClick = (id) => { | ||
setShowDeleteDialog(true); | ||
const editSelection = clientData.find(client => client.id === id); | ||
setClientToDelete(editSelection); | ||
}; | ||
|
||
const handleSelectChange = (event) => { | ||
clients.show(params.clientId,`?time_frame=${event.target.value}`) | ||
.then((res) => { | ||
const sanitized = unmapClientDetails(res); | ||
setClientData(sanitized.projectDetails); | ||
setClientDetails(sanitized.clientDetails); | ||
setTotalMinutes(sanitized.totalMinutes); | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
setAuthHeaders(); | ||
registerIntercepts(); | ||
clients.show(params.clientId, "?time_frame=week") | ||
.then((res) => { | ||
const sanitized = unmapClientDetails(res); | ||
setClientDetails(sanitized.clientDetails); | ||
setClientData(sanitized.projectDetails); | ||
setTotalMinutes(sanitized.totalMinutes); | ||
}); | ||
}, []); | ||
|
||
const tableHeader = [ | ||
{ | ||
Header: "PROJECT", | ||
accessor: "col1", // accessor is the "key" in the data | ||
cssClass: "" | ||
}, | ||
{ | ||
Header: "TEAM", | ||
accessor: "col2", | ||
cssClass: "" | ||
}, | ||
{ | ||
Header: "HOURS LOGGED", | ||
accessor: "col3", | ||
cssClass: "text-right" // accessor is the "key" in the data | ||
} | ||
]; | ||
|
||
const amountBox = [{ | ||
title: "OVERDUE", | ||
amount: "$35.5k" | ||
}, | ||
{ | ||
title: "OUTSTANDING", | ||
amount: "$24.3k" | ||
}]; | ||
|
||
const tableData = getTableData(clientData); | ||
|
||
return ( | ||
<> | ||
<ToastContainer /> | ||
<Header clientDetails={clientDetails} /> | ||
<div> | ||
{ isAdminUser && <div className="bg-miru-gray-100 py-10 px-10"> | ||
<div className="flex justify-end"> | ||
<select onChange={handleSelectChange} className="px-3 | ||
py-1.5 | ||
text-base | ||
font-normal | ||
bg-transparent bg-clip-padding bg-no-repeat | ||
border-none | ||
transition | ||
ease-in-out | ||
m-0 | ||
focus:outline-none | ||
text-miru-han-purple-1000"> | ||
<option className="text-miru-dark-purple-600" value="week"> | ||
THIS WEEK | ||
</option> | ||
<option className="text-miru-dark-purple-600" value="month"> | ||
This MONTH | ||
</option> | ||
<option className="text-miru-dark-purple-600" value="year"> | ||
THIS YEAR | ||
</option> | ||
</select> | ||
</div> | ||
{clientData && <ChartBar data={clientData} totalMinutes={totalMinutes} />} | ||
<AmountBoxContainer amountBox = {amountBox} /> | ||
</div> | ||
} | ||
<div className="flex flex-col"> | ||
<div className="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8"> | ||
<div className="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8"> | ||
<div className="overflow-hidden"> | ||
{ clientData && <Table | ||
handleEditClick={handleEditClick} | ||
handleDeleteClick={handleDeleteClick} | ||
hasRowIcons={true} | ||
tableHeader={tableHeader} | ||
tableRowArray={tableData} | ||
/> } | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{showEditDialog && | ||
<EditClient | ||
setShowEditDialog={setShowEditDialog} | ||
client={clientToEdit} | ||
/> | ||
} | ||
{showDeleteDialog && ( | ||
<DeleteClient | ||
setShowDeleteDialog={setShowDeleteDialog} | ||
client={clientToDelete} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default ClientList; |
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,34 @@ | ||
import * as React from "react"; | ||
import { MagnifyingGlass, Plus } from "phosphor-react"; | ||
|
||
const Header = ({ setnewClient }) => ( | ||
<div className="sm:flex mt-6 mb-3 sm:items-center sm:justify-between"> | ||
<h2 className="header__title"> | ||
Clients | ||
</h2> | ||
<div className="header__searchWrap"> | ||
<div className="header__searchInnerWrapper"> | ||
<input | ||
type="search" | ||
className="header__searchInput" | ||
placeholder="Search" | ||
/> | ||
<button className="absolute inset-y-0 right-0 pr-3 flex items-center cursor-pointer"> | ||
<MagnifyingGlass size={12} /> | ||
</button> | ||
</div> | ||
</div> | ||
<div className="flex"> | ||
<button | ||
type="button" | ||
className="header__button" | ||
onClick={() => setnewClient(true)} | ||
> | ||
<Plus weight="fill" size={16} /> | ||
<span className="ml-2 inline-block">NEW CLIENT</span> | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
|
||
export default Header; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 space indent