Skip to content

Commit

Permalink
Merge pull request #14 from newrice/dev
Browse files Browse the repository at this point in the history
[fix] Make using store as current group user data
  • Loading branch information
newrice authored Mar 2, 2021
2 parents 4064555 + c2aab00 commit 234ed83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 28 deletions.
10 changes: 1 addition & 9 deletions src/api/basicApi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getData, BASE_BACKEND } from "./api-base";
import settings from "../settings";
import { IApiResponseBase, ICategory, IUser, QueryParams } from "../types";
import { IApiResponseBase, ICategory, QueryParams } from "../types";

export const fetchDataBase = <T>(
url: string,
Expand Down Expand Up @@ -30,11 +30,3 @@ export const fetchCategories = (
groupId,
`${BASE_BACKEND}${settings.url.categories}`,
);

export const fetchUsers = (
groupId: string,
): Promise<IApiResponseBase<IUser[] | undefined>> =>
fetchGroupedDataBase<IUser[] | undefined>(
groupId,
`${BASE_BACKEND}${settings.url.users}`,
);
25 changes: 6 additions & 19 deletions src/features/calendars/controller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ import { useDispatch, useSelector } from "react-redux";
import { groupBy, isArray, isEmpty } from "lodash";
import CalendarForm from "./CalendarForm";
import { setProgress, setSnackState } from "../feedback/feedbackSlice";
import { selectCurrentGroup } from "../group/groupSlice";
import {
selectCurrentGroup,
selectCurrentGroupUser,
} from "../group/groupSlice";
import {
createCalendar,
deleteCalendar,
fetchCalendars,
updateCalendar,
fetchUsers,
} from "../../api";
import {
IApiResponseBase,
ICalendar,
ICalendarBase,
ICalendarResponse,
IUser,
} from "../../types";
import { isApiError, createSnackState } from "../../utils";
// FIXME:
Expand All @@ -35,9 +36,10 @@ const calendarGroupBy = (calendars: ICalendarResponse[]) => {

const CalendarController = (): JSX.Element => {
const currentGroup = useSelector(selectCurrentGroup);
const users = useSelector(selectCurrentGroupUser);
const dispatch = useDispatch();
const [calendars, setCalendars] = useState<ICalendarResponse[]>([]);
const [users, setUsers] = useState<IUser[]>([]);
// const [users, setUsers] = useState<IUser[]>([]);
const [refresh, setRefresh] = useState<boolean>(false);

useEffect(() => {
Expand All @@ -60,21 +62,6 @@ const CalendarController = (): JSX.Element => {
getDatas();
}, [refresh, currentGroup]);

useEffect(() => {
const getDatas = async () => {
const data = await fetchUsers(currentGroup.id);
const { error } = isApiError(data, true);
if (!error)
setUsers(
data.body && !isEmpty(data.body) && isArray(data.body)
? data.body
: [],
);
// setUsers(usersData);
};
getDatas();
}, [currentGroup]);

const responseHandler = useCallback(
(res: IApiResponseBase<undefined>, withBody?: boolean) => {
const { error, message } = isApiError(res, withBody);
Expand Down

0 comments on commit 234ed83

Please sign in to comment.