mirror of
https://github.com/gnmyt/LicenseAPI.git
synced 2026-01-11 10:41:46 +00:00
Implement license search in Licenses.jsx
This commit is contained in:
@ -19,6 +19,8 @@ export const Licenses = () => {
|
|||||||
const [paginationModel, setPaginationModel] = useState(JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY_PAGINATION))
|
const [paginationModel, setPaginationModel] = useState(JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY_PAGINATION))
|
||||||
|| {page: 1, pageSize: 25, rowCount: 0});
|
|| {page: 1, pageSize: 25, rowCount: 0});
|
||||||
|
|
||||||
|
const [search, setSearch] = useState("");
|
||||||
|
|
||||||
const [columnSettings, setColumnSettings] = useState(JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY_COLUMNS)) || {});
|
const [columnSettings, setColumnSettings] = useState(JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY_COLUMNS)) || {});
|
||||||
const [disabledColumns, setDisabledColumns] = useState(JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY_DISPLAYED_COLUMNS)) || []);
|
const [disabledColumns, setDisabledColumns] = useState(JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY_DISPLAYED_COLUMNS)) || []);
|
||||||
|
|
||||||
@ -30,7 +32,7 @@ export const Licenses = () => {
|
|||||||
const fetchLicenses = async () => {
|
const fetchLicenses = async () => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
const data = await getRequest(`/license/${currentProject.id}/list?limit=${paginationModel.pageSize}&page=${paginationModel.page}`);
|
const data = await getRequest(`/license/${currentProject.id}/list?limit=${paginationModel.pageSize}&page=${paginationModel.page}&search=${search}`);
|
||||||
setRows(data?.licenses.map((license) => ({id: license.key, ...license})) || []);
|
setRows(data?.licenses.map((license) => ({id: license.key, ...license})) || []);
|
||||||
setPaginationModel(prev => ({...prev, rowCount: data.total}));
|
setPaginationModel(prev => ({...prev, rowCount: data.total}));
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
@ -60,6 +62,10 @@ export const Licenses = () => {
|
|||||||
localStorage.setItem(LOCAL_STORAGE_KEY_COLUMNS, JSON.stringify(columnSettings));
|
localStorage.setItem(LOCAL_STORAGE_KEY_COLUMNS, JSON.stringify(columnSettings));
|
||||||
}, [columnSettings]);
|
}, [columnSettings]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchLicenses();
|
||||||
|
}, [search]);
|
||||||
|
|
||||||
const deleteLicense = async (licenseKey) => {
|
const deleteLicense = async (licenseKey) => {
|
||||||
try {
|
try {
|
||||||
await deleteRequest(`/license/${currentProject.id}/${encodeURIComponent(licenseKey)}`);
|
await deleteRequest(`/license/${currentProject.id}/${encodeURIComponent(licenseKey)}`);
|
||||||
@ -110,6 +116,7 @@ export const Licenses = () => {
|
|||||||
|
|
||||||
<Stack justifyContent="space-between" direction="row" sx={{mb: 2}} alignItems="center">
|
<Stack justifyContent="space-between" direction="row" sx={{mb: 2}} alignItems="center">
|
||||||
<TextField variant="outlined" size="small" placeholder="Lookup license"
|
<TextField variant="outlined" size="small" placeholder="Lookup license"
|
||||||
|
value={search} onChange={(e) => setSearch(e.target.value)}
|
||||||
InputProps={{startAdornment: <Search sx={{mr: 1}}/>}}/>
|
InputProps={{startAdornment: <Search sx={{mr: 1}}/>}}/>
|
||||||
|
|
||||||
<Button variant="contained" color="primary" onClick={() => setDialogOpen(true)}>
|
<Button variant="contained" color="primary" onClick={() => setDialogOpen(true)}>
|
||||||
|
|||||||
Reference in New Issue
Block a user