Skip to content

Commit

Permalink
Add patch to remove roles
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas committed Dec 4, 2024
1 parent 1f99acc commit 9524069
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export default function CopyToClipboard({ value }: IProps) {
return (
<div className="copy-to-clipboard">
<Paragraph className={isNumeric ? "numeric" : ""}>{value}</Paragraph>
<Tooltip content="kopiert" open={copied === value} >
<Tooltip content="kopiert" open={copied === value} placement="right" >
<Button
icon
color="first"
color="second"
variant="tertiary"
size="small"
onClick={() => {
Expand Down
81 changes: 59 additions & 22 deletions src/oed-testdata.client/src/components/estateCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,53 @@
import { useState } from "react";
import { Button, Heading, Label, Spinner } from "@digdir/designsystemet-react";
import "./style.css";
import CopyToClipboard from "../copyToClipboard";
import { ArrowCirclepathIcon } from "@navikt/aksel-icons";
import { ArrowCirclepathIcon, PadlockUnlockedIcon } from "@navikt/aksel-icons";
import { Estate } from "../../interfaces/IEstate";
import { ESTATE_API } from "../../utils/constants";
import { useState } from "react";

interface IProps {
data: Estate;
}

export default function EstateCard({ data }: IProps) {
const [loading, setLoading] = useState(false);

const handleResetEstate = async () => {
setLoading(true);
const response = await fetch(ESTATE_API, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ estateSsn: data.estateSsn }),
});
const [loadingResetEstate, setLoadingResetEstate] = useState(false);
const [loadingRemoveRoles, setLoadingRemoveRoles] = useState(false);

/* TODO: handle response success or failure with toasts */

if (!response.ok) {
console.error("Error resetting estate:", response.statusText);
const handleResetEstate = async () => {
try {
setLoadingResetEstate(true);
await fetch(`${ESTATE_API}${data.estateSsn}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ estateSsn: data.estateSsn }),
});
} catch (error) {
console.error("Error resetting estate:", error);
} finally {
setLoadingResetEstate(false);
}
};

setLoading(false);
const handleRemoveRoles = async () => {
const estateUrl = `${ESTATE_API}${data.estateSsn}`;
try {
setLoadingRemoveRoles(true);
await fetch(`${estateUrl}/roles`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ estateSsn: data.estateSsn, status: "FEILFORT" }),
});
} catch (error) {
console.error("Error removing roles:", error);
} finally {
setLoadingRemoveRoles(false);
}
};

return (
Expand Down Expand Up @@ -58,20 +76,39 @@ export default function EstateCard({ data }: IProps) {

<div className="card__footer">
<Button
color="first"
size="sm"
variant="secondary"
onClick={handleRemoveRoles}
disabled={loadingRemoveRoles}
aria-disabled={loadingRemoveRoles}
>
{loadingRemoveRoles ? (
<>
<Spinner variant="interaction" title="loading" size="sm" />
Laster...
</>
) : (
<>
<PadlockUnlockedIcon title="fjern roller" fontSize="1.5rem" />
Fjern roller
</>
)}
</Button>
<Button
variant="secondary"
color="danger"
onClick={handleResetEstate}
aria-disabled={loading}
disabled={loadingResetEstate}
aria-disabled={loadingResetEstate}
>
{loading ? (
{loadingResetEstate ? (
<>
<Spinner variant="interaction" title="loading" size="sm" />
Laster...
</>
) : (
<>
<ArrowCirclepathIcon title="a11y-title" fontSize="1.5rem" />
Nullstill
Nullstill bo
</>
)}
</Button>
Expand Down
4 changes: 4 additions & 0 deletions src/oed-testdata.client/src/components/estateCard/style.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.card {
height: 100%;
display: flex;
flex-direction: column;
border: 2px dashed var(--fds-semantic-border-neutral-default);
Expand All @@ -12,6 +13,7 @@

.card__content {
padding: 1rem 1.5rem;
flex-grow: 1;
ul {
margin-bottom: 1rem;
}
Expand All @@ -21,6 +23,8 @@
flex-direction: row;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 1rem;
padding: 0.5rem 1rem;
background-color: var(--fds-semantic-surface-neutral-subtle);
margin-bottom: 1rem;
Expand Down

0 comments on commit 9524069

Please sign in to comment.