Skip to content

Commit bbbb4b5

Browse files
added dev flag
1 parent 4dde567 commit bbbb4b5

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

src/app/services/logsApi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ type LogsQueryParams = {
77
dev?: boolean;
88
};
99

10-
type LogEntry = {
10+
export type LogEntry = {
1111
type: string;
1212
timestamp?: string | number;
1313
from?: string | number;
1414
until?: string | number;
1515
taskTitle?: string;
1616
};
1717

18-
type LogsResponse = {
18+
export type LogsResponse = {
1919
data: LogEntry[];
2020
message?: string;
2121
};

src/components/Calendar/UserSearchField.tsx

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { useState, useEffect, ChangeEvent, useRef } from 'react';
2+
import { useRouter } from 'next/router';
23
import classNames from './UserSearchField.module.scss';
34
import { useGetAllUsersQuery } from '@/app/services/usersApi';
45
import { useLazyGetLogsQuery } from '@/app/services/logsApi';
6+
import { logs } from '@/constants/calendar';
57
import { userDataType } from '@/interfaces/user.type';
68
import { useOutsideAlerter } from '@/hooks/useOutsideAlerter';
79

@@ -31,6 +33,9 @@ type CalendarData = {
3133
};
3234

3335
const SearchField = ({ onSearchTextSubmitted, loading }: SearchFieldProps) => {
36+
const router = useRouter();
37+
const isDevMode = router.query.dev === 'true';
38+
3439
const handleOutsideClick = () => {
3540
setDisplayList([]);
3641
};
@@ -66,7 +71,15 @@ const SearchField = ({ onSearchTextSubmitted, loading }: SearchFieldProps) => {
6671
return;
6772
}
6873

69-
// Fetch logs for OOO data only
74+
// Feature flag: Use different data sources based on dev mode
75+
if (!isDevMode) {
76+
// Non-dev mode: Use mock data from constants (original behavior)
77+
const userData = data.find((item: any) => item.userId === user.id);
78+
onSearchTextSubmitted(user, userData ? [userData] : []);
79+
return;
80+
}
81+
82+
// Dev mode: Fetch real OOO data from logs API
7083
const logsResult = await triggerGetLogs({
7184
username: user.username || undefined,
7285
type: 'REQUEST_CREATED',
@@ -95,16 +108,25 @@ const SearchField = ({ onSearchTextSubmitted, loading }: SearchFieldProps) => {
95108
onSearchTextSubmitted(user, mapped);
96109
};
97110

98-
const { data: userData, isLoading } = useGetAllUsersQuery();
111+
const { data: userData, isError, isLoading } = useGetAllUsersQuery();
99112
const [usersList, setUsersList] = useState<userDataType[]>([]);
100113
const [displayList, setDisplayList] = useState<userDataType[]>([]);
114+
const [data, setData] = useState([]);
101115

102116
useEffect(() => {
103117
if (userData?.users) {
104118
const users: userDataType[] = userData.users;
105119
const filteredUsers: userDataType[] = users.filter(
106120
(user: userDataType) => !user.incompleteUserDetails
107121
);
122+
const logData: any = filteredUsers.map((user: userDataType) => {
123+
const log = logs[Math.floor(Math.random() * 4)];
124+
return {
125+
data: log,
126+
userId: user.id,
127+
};
128+
});
129+
setData(logData);
108130
setUsersList(filteredUsers);
109131
}
110132
}, [isLoading, userData]);
@@ -167,10 +189,7 @@ const SearchField = ({ onSearchTextSubmitted, loading }: SearchFieldProps) => {
167189
<button
168190
className={classNames.userSearchSubmitButton}
169191
disabled={
170-
loading ||
171-
isLogsFetching ||
172-
!(searchText ?? '').trim() ||
173-
!isValidUsername()
192+
loading || !(searchText ?? '').trim() || !isValidUsername()
174193
}
175194
>
176195
Submit

0 commit comments

Comments
 (0)