Skip to content

Commit

Permalink
Fix archive button saving issue (#217)
Browse files Browse the repository at this point in the history
* fix archive button saving issue

* fix style errors

---------

Co-authored-by: axgu <86838870+axgu@users.noreply.github.com>
  • Loading branch information
michellejli77 and axgu authored Mar 23, 2024
1 parent 51361cc commit 529aa82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 8 additions & 1 deletion client/src/components/ArchiveButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Props = {
// eslint-disable-next-line @typescript-eslint/ban-types
fetchItems: Function;
disabled: boolean;
handleSubmit: () => void;
};

function exampleReducer(dispatchState: any, action: any) {
Expand All @@ -26,7 +27,12 @@ function exampleReducer(dispatchState: any, action: any) {
}
}

const ArchiveButton: React.FC<Props> = ({ id, fetchItems, disabled }) => {
const ArchiveButton: React.FC<Props> = ({
id,
fetchItems,
disabled,
handleSubmit,
}) => {
const [dispatchState, dispatch] = React.useReducer(exampleReducer, {
closeOnEscape: false,
closeOnDimmerClick: false,
Expand Down Expand Up @@ -73,6 +79,7 @@ const ArchiveButton: React.FC<Props> = ({ id, fetchItems, disabled }) => {
<p>Are you sure you wish to archive this item?</p>
<Button
onClick={() => {
handleSubmit();
axios
.post("/api/items/archive", {
token: localStorage.getItem("lnf_token"),
Expand Down
9 changes: 7 additions & 2 deletions client/src/components/EditItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ function EditItem(props: {
});
};

const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
const handleSubmitHelper = () => {
const {
date,
name,
Expand Down Expand Up @@ -283,6 +282,11 @@ function EditItem(props: {
);
};

const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
handleSubmitHelper();
};

const isAdmin = props.user?.permissions.some((value) =>
value.includes(PermissionType.ADMIN)
);
Expand Down Expand Up @@ -479,6 +483,7 @@ function EditItem(props: {
value.includes(PermissionType.ADMIN)
)
}
handleSubmit={handleSubmitHelper}
/>
) : null}
</div>
Expand Down

0 comments on commit 529aa82

Please sign in to comment.