-
Notifications
You must be signed in to change notification settings - Fork 42
register #2113
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
base: console
Are you sure you want to change the base?
register #2113
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -236,4 +236,55 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
> div:nth-of-type(1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
width: 69%; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
.attendanceCell { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
display: flex; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+241
to
+243
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Enhance flex container properties. The flex container could benefit from additional properties to better control alignment and spacing. .attendanceCell {
display: flex;
+ align-items: center;
+ gap: 0.5rem;
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
.chip-container { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
display: flex; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
align-items: center; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
gap: 0.5rem; /* Adjust the spacing between chips and the button */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
.chip-wrapper { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
display: inline-flex; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
.more-button { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
margin-left: 0.5rem; /* Adjust the spacing between chips and the + button */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+245
to
+257
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Improve documentation and maintain consistency with design tokens. While the layout structure is good, consider:
.chip-container {
display: flex;
align-items: center;
- gap: 0.5rem; /* Adjust the spacing between chips and the button */
+ gap: var(--spacing-xs, 0.5rem);
}
.more-button {
- margin-left: 0.5rem; /* Adjust the spacing between chips and the + button */
+ margin-left: var(--spacing-xs, 0.5rem);
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
/* Container for the progress bar */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.progress-bar-container { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
position: relative; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
width: 20rem; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
max-width: 20rem; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
height: 20px; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
background-color: #f3f3f3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
border-radius: 10px; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
overflow: hidden; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
border: 1px solid #d6d5d4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
/* The fill of the progress bar */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.progress-bar-fill { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
height: 100%; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
background-color: #2BD27F; /* Use your PRIMARY_COLOR */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
transition: width 0.4s ease-in-out; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
display: flex; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
align-items: center; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
justify-content: center; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
/* Text inside the progress bar */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.progress-bar-text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
position: absolute; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
width: 100%; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
text-align: center; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
font-size: 14px; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
color: #fff; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
font-weight: bold; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
pointer-events: none; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+259
to
+290
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance progress bar accessibility and maintainability. The progress bar implementation could be improved in several ways:
.progress-bar-container {
position: relative;
- width: 20rem;
- max-width: 20rem;
+ width: var(--progress-bar-width, 20rem);
+ max-width: var(--progress-bar-max-width, 20rem);
height: 20px;
- background-color: #f3f3f3;
+ background-color: var(--progress-bar-bg, #f3f3f3);
border-radius: 10px;
overflow: hidden;
- border: 1px solid #d6d5d4;
+ border: 1px solid var(--border-color, #d6d5d4);
+ &:hover {
+ border-color: var(--border-color-hover, #a8a29e);
+ }
+ &:focus-within {
+ outline: 2px solid var(--focus-color, #0B4B66);
+ outline-offset: 2px;
+ }
}
.progress-bar-fill {
height: 100%;
- background-color: #2BD27F; /* Use your PRIMARY_COLOR */
+ background-color: var(--progress-success, #2BD27F);
transition: width 0.4s ease-in-out;
display: flex;
align-items: center;
justify-content: center;
}
.progress-bar-text {
position: absolute;
width: 100%;
text-align: center;
- font-size: 14px;
+ font-size: var(--text-sm, 14px);
- color: #fff;
+ color: var(--text-white, #fff);
font-weight: bold;
pointer-events: none;
+ user-select: none;
} Add the following HTML attributes to the progress bar container for better accessibility: <div
class="progress-bar-container"
role="progressbar"
aria-valuenow="75"
aria-valuemin="0"
aria-valuemax="100"
>
<!-- progress bar content -->
</div> |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,257 @@ | ||
import React, { useState, useCallback, useEffect } from 'react'; | ||
import { Card, Button, PopUp, Loader, Chip, TextInput } from "@egovernments/digit-ui-components"; | ||
import DataTable from "react-data-table-component"; | ||
import { CustomSVG } from "@egovernments/digit-ui-components"; | ||
import { tableCustomStyle } from "./tableCustomStyle"; | ||
import { useTranslation } from "react-i18next"; | ||
import ProgressBar from './ProgressBar'; | ||
|
||
const SupervisorPopup = ({ setShowPopUp, supervisors }) => { | ||
const { t } = useTranslation(); | ||
return ( | ||
<PopUp | ||
className="wrapper-popup-boundary-chips" | ||
style={{ maxWidth: "40%" }} | ||
type="default" | ||
heading={t("SUPERVISORS_ASSIGNED")} | ||
footerChildren={[]} | ||
onOverlayClick={() => setShowPopUp(false)} | ||
onClose={() => setShowPopUp(false)} | ||
> | ||
<div className="digit-tag-container userAccessCell" | ||
style={{ | ||
display: "flex", | ||
flexWrap: "wrap", | ||
justifyContent: "flex-start", | ||
gap: "8px" | ||
}}> | ||
{supervisors.map((supervisor, index) => ( | ||
<Chip | ||
key={index} | ||
text={supervisor} | ||
hideClose={true} | ||
/> | ||
))} | ||
</div> | ||
</PopUp> | ||
); | ||
}; | ||
|
||
const IndividualUserTable = ({ tenantId, staffAttendeeIds = [], supervisorName = "" }) => { | ||
const { t } = useTranslation(); | ||
const [totalRows, setTotalRows] = useState(0); | ||
const [currentPage, setCurrentPage] = useState(1); | ||
const [rowsPerPage, setRowsPerPage] = useState(5); | ||
const [searchQuery, setSearchQuery] = useState(''); | ||
const [paginatedData, setPaginatedData] = useState([]); | ||
const [chipPopUpRowId, setChipPopUpRowId] = useState(null); | ||
|
||
const individualUsers = { | ||
url: `/health-individual/v1/_search`, | ||
params: { | ||
tenantId: tenantId, | ||
limit: 1000, | ||
offset: 0 | ||
}, | ||
body: { | ||
Individual: {}, | ||
}, | ||
}; | ||
Comment on lines
+49
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Consider pagination at API level The API call uses a hardcoded limit of 1000 records which could cause performance issues with large datasets. Consider implementing server-side pagination. params: {
tenantId: tenantId,
- limit: 1000,
- offset: 0
+ limit: rowsPerPage,
+ offset: (currentPage - 1) * rowsPerPage
},
|
||
|
||
const { isLoading, data, isFetching } = Digit.Hooks.useCustomAPIHook(individualUsers); | ||
|
||
const getDisplayData = useCallback(() => { | ||
if (!data?.Individual) return []; | ||
|
||
const filteredData = data.Individual.filter(user => { | ||
const userName = user.name?.givenName?.toLowerCase() || ''; | ||
return userName.includes(searchQuery.toLowerCase()); | ||
}).map(user => ({ | ||
...user, | ||
isAssigned: staffAttendeeIds.includes(user.id) | ||
})); | ||
|
||
setTotalRows(filteredData.length); | ||
|
||
const startIndex = (currentPage - 1) * rowsPerPage; | ||
const endIndex = startIndex + rowsPerPage; | ||
return filteredData.slice(startIndex, endIndex); | ||
}, [data, searchQuery, staffAttendeeIds, currentPage, rowsPerPage]); | ||
|
||
useEffect(() => { | ||
if (data?.Individual) { | ||
setPaginatedData(getDisplayData()); | ||
} | ||
}, [data, searchQuery, currentPage, rowsPerPage, getDisplayData]); | ||
|
||
const handlePaginationChange = (page) => { | ||
setCurrentPage(page); | ||
}; | ||
|
||
const handleRowsPerPageChange = (newPerPage) => { | ||
setRowsPerPage(newPerPage); | ||
setCurrentPage(1); | ||
}; | ||
|
||
const handleSearchChange = (e) => { | ||
setSearchQuery(e.target.value); | ||
setCurrentPage(1); | ||
}; | ||
|
||
const handleAssign = (userId) => { | ||
//code to be written | ||
}; | ||
|
||
const handleUnassign = (userId) => { | ||
//code to be written | ||
}; | ||
Comment on lines
+101
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Implement assign/unassign functionality The handleAssign and handleUnassign functions are currently empty placeholders. This could lead to a poor user experience as the buttons won't perform any action. Would you like me to help implement these functions or create GitHub issues to track their implementation? |
||
|
||
const columns = [ | ||
{ | ||
name: t('Name'), | ||
selector: row => row.name?.givenName || '', | ||
sortable: true, | ||
}, | ||
{ | ||
name: t('Mobile Number'), | ||
selector: row => row.mobileNumber || '', | ||
sortable: true, | ||
}, | ||
{ | ||
name: t("USER_TYPE"), | ||
selector: row => row?.userDetails?.type || '', | ||
sortable: true | ||
}, | ||
{ | ||
name: t('Assigned Supervisor'), | ||
selector: row => row.isAssigned ? supervisorName : t('Not Assigned'), | ||
sortable: true, | ||
grow: 2, | ||
cell: row => { | ||
const supervisors = row.isAssigned ? [supervisorName] : []; | ||
|
||
return ( | ||
<div className="digit-tag-container"> | ||
{supervisors.length > 0 ? ( | ||
<div className="chip-container"> | ||
{supervisors.slice(0, 2).map((supervisor, index) => ( | ||
<div key={index} className="chip-wrapper"> | ||
<Chip | ||
text={supervisor} | ||
hideClose={true} | ||
/> | ||
</div> | ||
))} | ||
|
||
{supervisors.length > 2 && ( | ||
<Button | ||
label={`+${supervisors.length - 2} ${t("ES_MORE")}`} | ||
variation="link" | ||
onClick={() => setChipPopUpRowId(row.id)} | ||
className="more-button" | ||
style={{ | ||
height: "2rem", | ||
minWidth: "4.188rem", | ||
minHeight: "2rem", | ||
padding: "0.5rem" | ||
}} | ||
textStyles={{ | ||
fontSize: "0.875rem", | ||
fontWeight: "400", | ||
color: "#C84C0E", | ||
}} | ||
/> | ||
)} | ||
|
||
{chipPopUpRowId === row.id && ( | ||
<SupervisorPopup | ||
setShowPopUp={setChipPopUpRowId} | ||
supervisors={supervisors} | ||
/> | ||
)} | ||
</div> | ||
) : ( | ||
<span className="text-gray-400">{t('Not Assigned')}</span> | ||
)} | ||
</div> | ||
); | ||
}, | ||
}, | ||
{ | ||
name: t('Actions'), | ||
cell: row => ( | ||
<div> | ||
{row.isAssigned ? ( | ||
<Button | ||
label={t('Unassign')} | ||
variation="secondary" | ||
icon="Close" | ||
onClick={() => handleUnassign(row.id)} | ||
/> | ||
) : ( | ||
<Button | ||
label={t('Assign')} | ||
variation="primary" | ||
icon="CheckCircle" | ||
onClick={() => handleAssign(row.id)} | ||
/> | ||
)} | ||
</div> | ||
) | ||
}, | ||
]; | ||
|
||
return ( | ||
<div className="w-full"> | ||
{isLoading && <Loader />} | ||
{!isLoading && ( | ||
<div> | ||
<Card type={"secondary"} style={{ maxWidth: "100%", overflow: "auto", marginBottom: "1rem" }}> | ||
<div> | ||
<div style={{ marginBottom: "0.5rem" }}>{t("USER_NAME")}</div> | ||
<TextInput | ||
style={{ maxWidth: "fit-content" }} | ||
disabled={false} | ||
className="textinput-example" | ||
type="text" | ||
name={t("USER_NAME")} | ||
value={searchQuery} | ||
onChange={handleSearchChange} | ||
placeholder={t("SEARCH_BY_NAME")} | ||
/> | ||
</div> | ||
</Card> | ||
|
||
<DataTable | ||
columns={columns} | ||
data={paginatedData} | ||
progressPending={isLoading || isFetching} | ||
progressComponent={<Loader />} | ||
pagination | ||
paginationServer | ||
customStyles={tableCustomStyle} | ||
paginationTotalRows={totalRows} | ||
onChangePage={handlePaginationChange} | ||
onChangeRowsPerPage={handleRowsPerPageChange} | ||
paginationPerPage={rowsPerPage} | ||
sortIcon={<CustomSVG.SortUp width="16px" height="16px" fill="#0b4b66" />} | ||
paginationRowsPerPageOptions={[5, 10, 15, 20]} | ||
noDataComponent={<div>{t('No records found')}</div>} | ||
/> | ||
|
||
{/* Progress Bar Section */} | ||
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginTop: "1rem" }}> | ||
<div style={{ display: "flex", alignItems: "center", gap: "1rem" }}> | ||
<span style={{ fontWeight: 600 }}>{t("REGISTER_ASSIGNED_USERS")}</span> | ||
<ProgressBar amount={40} total={100} /> | ||
<span style={{ fontWeight: 600 }}>{`${40}%`}</span> | ||
</div> | ||
</div> | ||
Comment on lines
+242
to
+249
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Replace hardcoded progress values The progress bar uses hardcoded values (40, 100) instead of calculating actual progress based on assigned users. - <ProgressBar amount={40} total={100} />
- <span style={{ fontWeight: 600 }}>{`${40}%`}</span>
+ <ProgressBar
+ amount={staffAttendeeIds.length}
+ total={data?.Individual?.length || 0}
+ />
+ <span style={{ fontWeight: 600 }}>
+ {`${Math.round((staffAttendeeIds.length / (data?.Individual?.length || 1)) * 100)}%`}
+ </span>
|
||
</div> | ||
)} | ||
</div> | ||
); | ||
|
||
}; | ||
|
||
export default IndividualUserTable; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,15 @@ | ||||||
import React from 'react'; | ||||||
|
||||||
const ProgressBar = ({ amount, total }) => { | ||||||
const percentage = Math.min((amount / total) * 100, 100); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle division by zero when calculating percentage The Apply this diff to safely handle the case when - const percentage = Math.min((amount / total) * 100, 100);
+ const percentage = total > 0 ? Math.min((amount / total) * 100, 100) : 0; This ensures that when 📝 Committable suggestion
Suggested change
|
||||||
|
||||||
return ( | ||||||
<div className="progress-bar-container"> | ||||||
<div className="progress-bar-fill" style={{ width: `${percentage}%` }}> | ||||||
<span className="progress-bar-text">{`${percentage.toFixed(1)}%`}</span> | ||||||
</div> | ||||||
</div> | ||||||
); | ||||||
}; | ||||||
|
||||||
export default ProgressBar; |
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.
🧹 Nitpick (assertive)
Consider using a more flexible width approach.
The hardcoded width of 69% might cause layout issues on different screen sizes. Consider using CSS Grid or Flexbox for better responsiveness.
📝 Committable suggestion