Skip to content

Commit

Permalink
fix(remove-instrument): use correct api to remove instrument
Browse files Browse the repository at this point in the history
  • Loading branch information
bas-kirill committed Aug 29, 2024
1 parent 9b94a9c commit 2ea0f1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@ import React from "react";
import styles from "./styles/RemoveInstrument.button.module.css";
import actionBtnStyle from "./styles/Action.button.module.css";
import { InstrumentDetail } from "generated/model";
import { RemoveFavoriteApi } from "generated/api/remove-favorite-api";
import { useDarkMode } from "shared/dark-mode/use-dark-mode";
import { apiConfig } from "shared/config/api";
import Jwt from "domain/model/jwt";
import { DeleteInstrumentByIdApi } from "generated/api/delete-instrument-by-id-api";

interface Props {
instrument: InstrumentDetail;
setSuccessModal: (successModal: boolean) => void;
setErrorModal: (errorModal: boolean) => void;
}

const removeFavoriteApi = new RemoveFavoriteApi(apiConfig);
const deleteInstrumentById = new DeleteInstrumentByIdApi(apiConfig)

export const RemoveInstrumentButton = (props: Props) => {
const { darkMode } = useDarkMode();

const handleOnDeleteInstrument = () => {
const removeFavorite = async () => {
const response = await removeFavoriteApi.removeFavorite(
props.instrument.instrument_id,
const response = await deleteInstrumentById.deleteInstrumentById(
props.instrument.instrument_id.instrument_id,
{
withCredentials: true,
headers: {
Authorization: `Bearer ${Jwt.extractFromCookie()!.toStringValue()}`,
},
},
);

)
if (response.status === 200) {
props.setSuccessModal(true);
return;
Expand Down
5 changes: 4 additions & 1 deletion client/src/shared/instrument-card/ui/InstrumentActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
} from "shared/instrument-card-actions";
import { COOKIE_JWT_KEY } from "shared/config/frontend";
import { getCookie } from "shared/cookie/cookie";
import { useNavigate } from "react-router-dom";
import { CATALOGUE } from "shared/config/paths";

interface Props {
instrument: InstrumentDetail;
Expand All @@ -24,6 +26,7 @@ interface Props {
export const InstrumentActions = (props: Props) => {
const jwt = useRef<string | undefined>(getCookie(COOKIE_JWT_KEY));

const navigate = useNavigate();
const [errorModal, setErrorModal] = useState<boolean>(false);
const [successModal, setSuccessModal] = useState<boolean>(false);

Expand Down Expand Up @@ -67,7 +70,7 @@ export const InstrumentActions = (props: Props) => {
opened={successModal}
closeModal={() => {
setSuccessModal(false);
window.location.reload();
navigate(CATALOGUE);
}}
>
<h1>✅Instrument deleted</h1>
Expand Down

0 comments on commit 2ea0f1e

Please sign in to comment.