-
Notifications
You must be signed in to change notification settings - Fork 21
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
1071972
commit cb810e8
Showing
14 changed files
with
897 additions
and
48 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
2 changes: 1 addition & 1 deletion
2
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/package.json
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
257 changes: 257 additions & 0 deletions
257
...icro-ui-internals/packages/modules/campaign-manager/src/components/IndividualUserTable.js
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,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: {}, | ||
}, | ||
}; | ||
|
||
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 | ||
}; | ||
|
||
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> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
|
||
}; | ||
|
||
export default IndividualUserTable; |
15 changes: 15 additions & 0 deletions
15
...ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/ProgressBar.js
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,15 @@ | ||
import React from 'react'; | ||
|
||
const ProgressBar = ({ amount, total }) => { | ||
const percentage = Math.min((amount / total) * 100, 100); | ||
|
||
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; |
Oops, something went wrong.