Skip to content

Commit cce98cd

Browse files
committed
Implemented pagination in login.
1 parent d65c2d5 commit cce98cd

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

client/packages/lowcoder/src/api/orgApi.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import {
1111
} from "redux/reduxActions/orgActions";
1212
import { ApiResponse, GenericApiResponse } from "./apiResponses";
1313
import {
14+
ApiPaginationResponse,
1415
fetchGroupUserRequestType,
16+
fetchOrgsByEmailRequestType,
1517
fetchOrgUserRequestType,
1618
GenericApiPaginationResponse,
1719
GroupUsersPaginationResponse,
@@ -166,6 +168,11 @@ export class OrgApi extends Api {
166168
static fetchOrgsByEmail(email: string): AxiosPromise<ApiResponse> {
167169
return Api.get(OrgApi.fetchOrgsByEmailURL(email));
168170
}
171+
172+
static fetchOrgsPaginationByEmail(request: fetchOrgsByEmailRequestType): AxiosPromise<ApiPaginationResponse> {
173+
const { email, ...rest } = request;
174+
return Api.get(OrgApi.fetchOrgsByEmailURL(email), {...rest});
175+
}
169176
}
170177

171178
export default OrgApi;

client/packages/lowcoder/src/pages/userAuth/formLoginSteps.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import { useDispatch, useSelector } from "react-redux";
2929
import history from "util/history";
3030
import ApplicationApi from "@lowcoder-ee/api/applicationApi";
3131
import { getServerSettings } from "@lowcoder-ee/redux/selectors/applicationSelector";
32+
import {fetchOrgPaginationByEmail} from "@lowcoder-ee/util/pagination/axios";
33+
import PaginationComp from "@lowcoder-ee/util/pagination/Pagination";
3234

3335
const StyledCard = styled.div<{$selected: boolean}>`
3436
display: flex;
@@ -91,6 +93,11 @@ type FormLoginProps = {
9193
organizationId?: string;
9294
}
9395

96+
interface ElementsState {
97+
elements: any;
98+
total: number;
99+
}
100+
94101
export default function FormLoginSteps(props: FormLoginProps) {
95102
const dispatch = useDispatch();
96103
const location = useLocation();
@@ -111,6 +118,21 @@ export default function FormLoginSteps(props: FormLoginProps) {
111118
const [skipWorkspaceStep, setSkipWorkspaceStep] = useState<boolean>(false);
112119
const [signupEnabled, setSignupEnabled] = useState<boolean>(true);
113120
const serverSettings = useSelector(getServerSettings);
121+
const [elements, setElements] = useState<ElementsState>({ elements: [], total: 0 });
122+
const [currentPage, setCurrentPage] = useState(1);
123+
const [pageSize, setPageSize] = useState(2);
124+
125+
useEffect(() => {
126+
fetchOrgPaginationByEmail({
127+
email: account,
128+
pageNum: currentPage,
129+
pageSize: pageSize
130+
}).then( result => {
131+
setElements({elements: result.data || [], total: result.total || 1})
132+
setOrgList(result.data)
133+
}
134+
)
135+
}, [pageSize, currentPage])
114136

115137
useEffect(() => {
116138
const { LOWCODER_EMAIL_SIGNUP_ENABLED } = serverSettings;
@@ -233,6 +255,14 @@ export default function FormLoginSteps(props: FormLoginProps) {
233255
{org.orgName}
234256
</StyledCard>
235257
))}
258+
{orgList.length > 10 ?
259+
<PaginationComp
260+
currentPage={currentPage}
261+
pageSize={pageSize}
262+
setPageSize={setPageSize}
263+
setCurrentPage={setCurrentPage}
264+
total={elements.total}
265+
/> : <></>}
236266
</AccountLoginWrapper>
237267
</>
238268
)

client/packages/lowcoder/src/util/pagination/axios.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
fetchAppRequestType, fetchDataSourcePaginationRequestType,
55
fetchDBRequestType,
66
fetchFolderRequestType,
7-
fetchGroupUserRequestType,
7+
fetchGroupUserRequestType, fetchOrgsByEmailRequestType,
88
fetchOrgUserRequestType, fetchQueryLibraryPaginationRequestType,
99
orgGroupRequestType
1010
} from "@lowcoder-ee/util/pagination/type";
@@ -147,4 +147,23 @@ export const fetchJsDSPaginationByApp = async (request: fetchDataSourcePaginatio
147147
error: error
148148
};
149149
}
150+
}
151+
152+
153+
154+
export const fetchOrgPaginationByEmail = async (request: fetchOrgsByEmailRequestType)=> {
155+
try {
156+
const response = await OrgApi.fetchOrgsPaginationByEmail(request);
157+
return {
158+
success: true,
159+
data: response.data.data,
160+
total: response.data.total
161+
}
162+
} catch (error: any) {
163+
console.error('Failed to fetch data:', error);
164+
return {
165+
success: false,
166+
error: error
167+
};
168+
}
150169
}

client/packages/lowcoder/src/util/pagination/type.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ export interface OrgUsersPaginationResponse {
3939
};
4040
}
4141

42+
export type ApiPaginationResponse = {
43+
total: number;
44+
success: boolean;
45+
code: number;
46+
message: string;
47+
data: any;
48+
};
49+
50+
4251
export interface fetchAppRequestType {
4352
pageNum?: number;
4453
pageSize?: number;
@@ -88,4 +97,10 @@ export interface fetchDataSourcePaginationRequestType {
8897
name?: string;
8998
pageNum?: number;
9099
pageSize?: number;
100+
}
101+
102+
export interface fetchOrgsByEmailRequestType {
103+
email: string;
104+
pageNum?: number;
105+
pageSize?: number;
91106
}

0 commit comments

Comments
 (0)