Skip to content

Commit

Permalink
fix: mutation of states (#256)
Browse files Browse the repository at this point in the history
* feat: label grouping, fix: new states response

* fix: mutation of states
  • Loading branch information
aaryan610 authored Feb 8, 2023
1 parent bd399d6 commit 8e3541b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 29 deletions.
4 changes: 2 additions & 2 deletions apps/app/components/states/create-update-state-inline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import useToast from "hooks/use-toast";
// ui
import { Button, CustomSelect, Input } from "components/ui";
// types
import type { IState } from "types";
import type { IState, StateResponse } from "types";
// fetch-keys
import { STATE_LIST } from "constants/fetch-keys";
// constants
Expand Down Expand Up @@ -85,7 +85,7 @@ export const CreateUpdateStateInline: React.FC<Props> = ({
await stateService
.createState(workspaceSlug, projectId, { ...payload })
.then((res) => {
mutate<IState[]>(STATE_LIST(projectId), (prevData) => [...(prevData ?? []), res]);
mutate(STATE_LIST(projectId));
handleClose();

setToastAlert({
Expand Down
16 changes: 2 additions & 14 deletions apps/app/components/states/create-update-state-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const CreateUpdateStateModal: React.FC<Props> = ({
await stateService
.createState(workspaceSlug as string, projectId, payload)
.then((res) => {
mutate<IState[]>(STATE_LIST(projectId), (prevData) => [...(prevData ?? []), res], false);
mutate(STATE_LIST(projectId));
onClose();
})
.catch((err) => {
Expand All @@ -95,19 +95,7 @@ export const CreateUpdateStateModal: React.FC<Props> = ({
await stateService
.updateState(workspaceSlug as string, projectId, data.id, payload)
.then((res) => {
mutate<IState[]>(
STATE_LIST(projectId),
(prevData) => {
const newData = prevData?.map((item) => {
if (item.id === res.id) {
return res;
}
return item;
});
return newData;
},
false
);
mutate(STATE_LIST(projectId));
onClose();
})
.catch((err) => {
Expand Down
6 changes: 1 addition & 5 deletions apps/app/components/states/delete-state-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ export const DeleteStateModal: React.FC<Props> = ({ isOpen, onClose, data }) =>
await stateServices
.deleteState(workspaceSlug as string, data.project, data.id)
.then(() => {
mutate<IState[]>(
STATE_LIST(data.project),
(prevData) => prevData?.filter((state) => state.id !== data?.id),
false
);
mutate(STATE_LIST(data.project));
handleClose();

setToastAlert({
Expand Down
5 changes: 1 addition & 4 deletions apps/app/helpers/state.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ export const orderStateGroups = (unorderedStateGroups: StateResponse) =>

export const getStatesList = (stateGroups: any): IState[] => {
// order the unordered state groups first
const orderedStateGroups = Object.assign(
{ backlog: [], unstarted: [], started: [], completed: [], cancelled: [] },
stateGroups
);
const orderedStateGroups = orderStateGroups(stateGroups);

// extract states from the groups and return them
return Object.keys(orderedStateGroups)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ const StatesSettings: NextPage<UserAuth> = (props) => {
: null
);
const orderedStateGroups = orderStateGroups(states ?? {});

const statesList = getStatesList(orderStateGroups ?? {});
const statesList = getStatesList(orderedStateGroups ?? {});

return (
<>
<DeleteStateModal
isOpen={!!selectDeleteState}
data={statesList?.find((state) => state.id === selectDeleteState) ?? null}
data={statesList?.find((s) => s.id === selectDeleteState) ?? null}
onClose={() => setSelectDeleteState(null)}
/>
<AppLayout
Expand Down Expand Up @@ -115,7 +114,7 @@ const StatesSettings: NextPage<UserAuth> = (props) => {
<div
key={state.id}
className={`flex items-center justify-between gap-2 border-b bg-gray-50 p-3 ${
Boolean(activeGroup !== key) ? "last:border-0" : ""
activeGroup !== key ? "last:border-0" : ""
}`}
>
<div className="flex items-center gap-2">
Expand Down

1 comment on commit 8e3541b

@vercel
Copy link

@vercel vercel bot commented on 8e3541b Feb 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

plane-dev – ./apps/app

plane-dev-git-develop-caravel.vercel.app
plane-dev.vercel.app
plane-dev-caravel.vercel.app

Please sign in to comment.