forked from github/plane
feat: inbox (#1023)
* dev: initialize inbox * dev: inbox and inbox issues models, views and serializers * dev: issue object filter for inbox * dev: filter for search issues * dev: inbox snooze and duplicates * dev: set duplicate to null by default * feat: inbox ui and services * feat: project detail in inbox * style: layout, popover, icons, sidebar * dev: default inbox for project and pending issues count * dev: fix exception when creating default inbox * fix: empty state for inbox * dev: auto issue state updation when rejected or marked duplicate * fix: inbox update status * fix: hydrating chose with old values filters workflow * feat: inbox issue filtering * fix: issue inbox filtering * feat: filter inbox issues * refactor: analytics, border colors * dev: filters and views for inbox * dev: source for inboxissue and update list inbox issue * dev: update list endpoint to house filters and additional data * dev: bridge id for list * dev: remove print logs * dev: update inbox issue workflow * dev: add description_html in issue details * fix: inbox track event auth, chore: inbox issue action authorization * fix: removed unnecessary api calls * style: viewed issues * fix: priority validation * dev: remove print logs * dev: update issue inbox update workflow * chore: added inbox view context * fix: type errors * fix: build errors and warnings * dev: update issue inbox workflow and log all the changes * fix: filters logic, sidebar fields to show * dev: update issue filtering status * chore: update create inbox issue modal, fix: mutation issues * dev: update issue accept workflow * chore: add comment to inbox issues * chore: remove inboxIssueId from url after deleting * dev: update the issue triage workflow * fix: mutation after issue status change * chore: issue details sidebar divider * fix: issue activity for inbox issues * dev: update inbox perrmissions * dev: create new permission layer * chore: auth layer for inbox * chore: show accepting status * chore: show issue status at the top of issue details --------- Co-authored-by: Dakshesh Jain <dakshesh.jain14@gmail.com> Co-authored-by: gurusainath <gurusainath007@gmail.com> Co-authored-by: Aaryan Khandelwal <aaryankhandu123@gmail.com>
This commit is contained in:
163
apps/app/contexts/inbox-view-context.tsx
Normal file
163
apps/app/contexts/inbox-view-context.tsx
Normal file
@@ -0,0 +1,163 @@
|
||||
import { createContext, useCallback, useEffect, useReducer } from "react";
|
||||
|
||||
import { useRouter } from "next/router";
|
||||
|
||||
import useSWR from "swr";
|
||||
|
||||
// components
|
||||
import ToastAlert from "components/toast-alert";
|
||||
// services
|
||||
import inboxServices from "services/inbox.service";
|
||||
// types
|
||||
import { IInboxFilterOptions } from "types";
|
||||
// fetch-keys
|
||||
import { INBOX_DETAILS } from "constants/fetch-keys";
|
||||
|
||||
export const inboxViewContext = createContext<ContextType>({} as ContextType);
|
||||
|
||||
type InboxViewProps = {
|
||||
filters: IInboxFilterOptions;
|
||||
};
|
||||
|
||||
type ReducerActionType = {
|
||||
type: "REHYDRATE_THEME" | "SET_FILTERS";
|
||||
payload?: Partial<InboxViewProps>;
|
||||
};
|
||||
|
||||
type ContextType = InboxViewProps & {
|
||||
setFilters: (filters: Partial<IInboxFilterOptions>) => void;
|
||||
};
|
||||
|
||||
type StateType = {
|
||||
filters: IInboxFilterOptions;
|
||||
};
|
||||
type ReducerFunctionType = (state: StateType, action: ReducerActionType) => StateType;
|
||||
|
||||
export const initialState: StateType = {
|
||||
filters: {
|
||||
priority: null,
|
||||
inbox_status: null,
|
||||
},
|
||||
};
|
||||
|
||||
export const reducer: ReducerFunctionType = (state, action) => {
|
||||
const { type, payload } = action;
|
||||
|
||||
switch (type) {
|
||||
case "REHYDRATE_THEME": {
|
||||
return { ...initialState, ...payload };
|
||||
}
|
||||
|
||||
case "SET_FILTERS": {
|
||||
const newState = {
|
||||
...state,
|
||||
filters: {
|
||||
...state.filters,
|
||||
...payload,
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
...state,
|
||||
...newState,
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const saveDataToServer = async (
|
||||
workspaceSlug: string,
|
||||
projectId: string,
|
||||
inboxId: string,
|
||||
state: any
|
||||
) => {
|
||||
await inboxServices.patchInbox(workspaceSlug, projectId, inboxId, {
|
||||
view_props: state,
|
||||
});
|
||||
};
|
||||
|
||||
export const InboxViewContextProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
|
||||
const router = useRouter();
|
||||
const { workspaceSlug, projectId, inboxId } = router.query;
|
||||
|
||||
const { data: inboxDetails, mutate: mutateInboxDetails } = useSWR(
|
||||
workspaceSlug && projectId && inboxId ? INBOX_DETAILS(inboxId.toString()) : null,
|
||||
workspaceSlug && projectId && inboxId
|
||||
? () =>
|
||||
inboxServices.getInboxById(
|
||||
workspaceSlug.toString(),
|
||||
projectId.toString(),
|
||||
inboxId.toString()
|
||||
)
|
||||
: null
|
||||
);
|
||||
|
||||
const setFilters = useCallback(
|
||||
(property: Partial<IInboxFilterOptions>) => {
|
||||
Object.keys(property).forEach((key) => {
|
||||
if (property[key as keyof typeof property]?.length === 0)
|
||||
property[key as keyof typeof property] = null;
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: "SET_FILTERS",
|
||||
payload: {
|
||||
filters: {
|
||||
...state.filters,
|
||||
...property,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!workspaceSlug || !projectId || !inboxId) return;
|
||||
|
||||
const newViewProps = {
|
||||
...state,
|
||||
filters: {
|
||||
...state.filters,
|
||||
...property,
|
||||
},
|
||||
};
|
||||
|
||||
mutateInboxDetails((prevData) => {
|
||||
if (!prevData) return prevData;
|
||||
|
||||
return {
|
||||
...prevData,
|
||||
view_props: newViewProps,
|
||||
};
|
||||
}, false);
|
||||
|
||||
saveDataToServer(
|
||||
workspaceSlug.toString(),
|
||||
projectId.toString(),
|
||||
inboxId.toString(),
|
||||
newViewProps
|
||||
);
|
||||
},
|
||||
[workspaceSlug, projectId, inboxId, mutateInboxDetails, state]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
dispatch({
|
||||
type: "REHYDRATE_THEME",
|
||||
payload: {
|
||||
...inboxDetails?.view_props,
|
||||
},
|
||||
});
|
||||
}, [inboxDetails]);
|
||||
|
||||
return (
|
||||
<inboxViewContext.Provider
|
||||
value={{
|
||||
filters: state.filters,
|
||||
setFilters,
|
||||
}}
|
||||
>
|
||||
<ToastAlert />
|
||||
{children}
|
||||
</inboxViewContext.Provider>
|
||||
);
|
||||
};
|
||||
@@ -633,6 +633,7 @@ export const IssueViewContextProvider: React.FC<{ children: React.ReactNode }> =
|
||||
mutateModuleDetails,
|
||||
viewId,
|
||||
mutateViewDetails,
|
||||
user,
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user