Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix archive button saving issue #217

Merged
merged 3 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading