mirror of
https://github.com/navikt/aksel.git
synced 2026-10-13 01:02:02 +00:00
Compare commits
15
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
638e8260b4 | ||
|
|
d991011690 | ||
|
|
b6086f7b1f | ||
|
|
05462081aa | ||
|
|
63e42de3ee | ||
|
|
2e85178166 | ||
|
|
456d4e2e07 | ||
|
|
b5a0cb8cdf | ||
|
|
a2af9bcc37 | ||
|
|
bd45754adb | ||
|
|
a882a8a389 | ||
|
|
d1606d358a | ||
|
|
bb87837632 | ||
|
|
9c8b2301ed | ||
|
|
54ba483d2d |
No files matched your search
@@ -25,6 +25,7 @@ jobs:
|
||||
|
||||
- name: add tokens to .env
|
||||
run: |
|
||||
echo "SLACK_BOT_TOKEN=${{ secrets.SLACK_BOT_TOKEN }}" >> aksel.nav.no/website/.env
|
||||
echo "SANITY_WRITE_KEY=${{ secrets.SANITY_FEEDBACK_WRITE_KEY }}" >> aksel.nav.no/website/.env
|
||||
echo "SANITY_PREVIEW_TOKEN=${{ secrets.SANITY_PREVIEW_TOKEN }}" >> aksel.nav.no/website/.env
|
||||
echo "SANITY_PRIVATE_NO_DRAFTS=${{ secrets.SANITY_PRIVATE_NO_DRAFTS }}" >> aksel.nav.no/website/.env
|
||||
|
||||
@@ -59,6 +59,7 @@ jobs:
|
||||
|
||||
- name: add tokens to .env
|
||||
run: |
|
||||
echo "SLACK_BOT_TOKEN=${{ secrets.SLACK_BOT_TOKEN }}" >> aksel.nav.no/website/.env
|
||||
echo "SANITY_WRITE_KEY=${{ secrets.SANITY_FEEDBACK_WRITE_KEY }}" >> aksel.nav.no/website/.env
|
||||
echo "SANITY_PREVIEW_TOKEN=${{ secrets.SANITY_PREVIEW_TOKEN }}" >> aksel.nav.no/website/.env
|
||||
echo "SANITY_PRIVATE_NO_DRAFTS=${{ secrets.SANITY_PRIVATE_NO_DRAFTS }}" >> aksel.nav.no/website/.env
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# @navikt/aksel-icons
|
||||
|
||||
## 6.3.4
|
||||
|
||||
## 6.3.3
|
||||
|
||||
## 6.3.2
|
||||
|
||||
## 6.3.1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/aksel-icons",
|
||||
"version": "6.3.2",
|
||||
"version": "6.3.4",
|
||||
"author": "Aksel | NAV",
|
||||
"homepage": "https://aksel.nav.no/ikoner",
|
||||
"repository": {
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# @navikt/aksel-stylelint
|
||||
|
||||
## 6.3.4
|
||||
|
||||
## 6.3.3
|
||||
|
||||
## 6.3.2
|
||||
|
||||
## 6.3.1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/aksel-stylelint",
|
||||
"version": "6.3.2",
|
||||
"version": "6.3.4",
|
||||
"author": "Aksel | NAV",
|
||||
"homepage": "https://aksel.nav.no/grunnleggende/kode/stylelint",
|
||||
"repository": {
|
||||
@@ -35,8 +35,8 @@
|
||||
"dev": "yarn watch:lint"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@navikt/ds-css": "^6.3.2",
|
||||
"@navikt/ds-tokens": "^6.3.2",
|
||||
"@navikt/ds-css": "^6.3.4",
|
||||
"@navikt/ds-tokens": "^6.3.4",
|
||||
"concurrently": "7.2.1",
|
||||
"postcss-selector-parser": "^6.0.13",
|
||||
"postcss-value-parser": "^4.2.0",
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
# @navikt/aksel
|
||||
|
||||
## 6.3.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`a2af9bcc3`](https://github.com/navikt/aksel/commit/a2af9bcc37eb12cc7cf3a1596d57dc0421898657)]:
|
||||
- @navikt/ds-css@6.3.4
|
||||
|
||||
## 6.3.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/ds-css@6.3.3
|
||||
|
||||
## 6.3.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/aksel",
|
||||
"version": "6.3.2",
|
||||
"version": "6.3.4",
|
||||
"description": "Aksel command line interface. Handles css-imports, codemods and more",
|
||||
"author": "Aksel | NAV designsystem team",
|
||||
"license": "MIT",
|
||||
@@ -29,7 +29,7 @@
|
||||
},
|
||||
"homepage": "https://aksel.nav.no/grunnleggende/kode/kommandolinje",
|
||||
"dependencies": {
|
||||
"@navikt/ds-css": "6.3.2",
|
||||
"@navikt/ds-css": "6.3.4",
|
||||
"axios": "1.6.0",
|
||||
"chalk": "4.1.0",
|
||||
"clipboardy": "^2.3.0",
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
# @navikt/ds-css
|
||||
|
||||
## 6.3.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- ReadMore: Padding-right på button er bumpet noen px ([#2806](https://github.com/navikt/aksel/pull/2806))
|
||||
|
||||
## 6.3.3
|
||||
|
||||
## 6.3.2
|
||||
|
||||
## 6.3.1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/ds-css",
|
||||
"version": "6.3.2",
|
||||
"version": "6.3.4",
|
||||
"description": "CSS for NAV Designsystem",
|
||||
"author": "Aksel | NAV designsystem team",
|
||||
"keywords": [
|
||||
@@ -27,7 +27,7 @@
|
||||
"css:get-version": "node config/get-version.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@navikt/ds-tokens": "^6.3.2",
|
||||
"@navikt/ds-tokens": "^6.3.4",
|
||||
"cssnano": "6.0.0",
|
||||
"fast-glob": "3.2.11",
|
||||
"lodash": "4.17.21",
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
gap: var(--a-spacing-05);
|
||||
color: var(--ac-read-more-text, var(--a-text-action));
|
||||
border-radius: var(--a-border-radius-small);
|
||||
padding: var(--a-spacing-1) var(--a-spacing-1) var(--a-spacing-1) var(--a-spacing-05);
|
||||
padding: var(--a-spacing-1) var(--a-spacing-2) var(--a-spacing-1) var(--a-spacing-05);
|
||||
text-align: start;
|
||||
}
|
||||
|
||||
.navds-read-more--small .navds-read-more__button {
|
||||
padding: var(--a-spacing-05) var(--a-spacing-1) var(--a-spacing-05) var(--a-spacing-05);
|
||||
padding: var(--a-spacing-05) var(--a-spacing-1-alt) var(--a-spacing-05) var(--a-spacing-05);
|
||||
}
|
||||
|
||||
@media (forced-colors: active) {
|
||||
|
||||
@@ -1,5 +1,29 @@
|
||||
# @navikt/ds-react
|
||||
|
||||
## 6.3.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Switch: Fikset edgecase der checked Switch var visuelt unchecked ([#2810](https://github.com/navikt/aksel/pull/2810))
|
||||
|
||||
- FileUpload.Dropzone: id prop settes på button ([#2817](https://github.com/navikt/aksel/pull/2817))
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/ds-tokens@6.3.4
|
||||
- @navikt/aksel-icons@6.3.4
|
||||
|
||||
## 6.3.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- FileUpload.Dropzone: Fiks feil med duplisert id ([#2805](https://github.com/navikt/aksel/pull/2805))
|
||||
|
||||
- useDatePicker: `isInvalid`-key i onValidate var hadde flipper boolean i noen tilfeller ([#2809](https://github.com/navikt/aksel/pull/2809))
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/ds-tokens@6.3.3
|
||||
- @navikt/aksel-icons@6.3.3
|
||||
|
||||
## 6.3.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/ds-react",
|
||||
"version": "6.3.2",
|
||||
"version": "6.3.4",
|
||||
"description": "React components from the Norwegian Labour and Welfare Administration.",
|
||||
"author": "Aksel, a team part of the Norwegian Labour and Welfare Administration.",
|
||||
"license": "MIT",
|
||||
@@ -562,8 +562,8 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@floating-ui/react": "0.25.4",
|
||||
"@navikt/aksel-icons": "^6.3.2",
|
||||
"@navikt/ds-tokens": "^6.3.2",
|
||||
"@navikt/aksel-icons": "^6.3.4",
|
||||
"@navikt/ds-tokens": "^6.3.4",
|
||||
"@radix-ui/react-tabs": "1.0.0",
|
||||
"@radix-ui/react-toggle-group": "1.0.0",
|
||||
"clsx": "^2.1.0",
|
||||
|
||||
@@ -160,6 +160,7 @@ export const UseDatepicker = () => {
|
||||
fromDate: new Date("Aug 23 2019"),
|
||||
toDate: new Date("Feb 23 2024"),
|
||||
onDateChange: console.log,
|
||||
onValidate: console.log,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -272,7 +272,7 @@ export const useDatepicker = (
|
||||
) {
|
||||
updateDate(undefined);
|
||||
updateValidation({
|
||||
isInvalid: isValidDate(day),
|
||||
isInvalid: !isValidDate(day),
|
||||
isWeekend: disableWeekends && isWeekend(day),
|
||||
isDisabled: disabled && isMatch(day, disabled),
|
||||
isValidDate: false,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Meta } from "@storybook/react";
|
||||
import { Meta, StoryObj } from "@storybook/react";
|
||||
import React, { useState } from "react";
|
||||
import { Button } from "../button";
|
||||
import Dropdown from "./Dropdown";
|
||||
@@ -6,10 +6,15 @@ import Dropdown from "./Dropdown";
|
||||
export default {
|
||||
title: "ds-react/Dropdown",
|
||||
component: Dropdown,
|
||||
} as Meta;
|
||||
parameters: {
|
||||
chromatic: { disable: true },
|
||||
},
|
||||
} satisfies Meta<typeof Dropdown>;
|
||||
|
||||
export const Default = () => {
|
||||
return (
|
||||
type Story = StoryObj<typeof Dropdown>;
|
||||
|
||||
export const Default: Story = {
|
||||
render: () => (
|
||||
<Dropdown onSelect={(event) => console.log(event)}>
|
||||
<Dropdown.Toggle>Toggle</Dropdown.Toggle>
|
||||
<Dropdown.Menu strategy="fixed">
|
||||
@@ -33,10 +38,10 @@ export const Default = () => {
|
||||
</Dropdown.Menu.List>
|
||||
</Dropdown.Menu>
|
||||
</Dropdown>
|
||||
);
|
||||
),
|
||||
};
|
||||
|
||||
export const DefaultOpen = {
|
||||
export const DefaultOpen: Story = {
|
||||
render: () => (
|
||||
<Dropdown onSelect={(event) => console.log(event)} defaultOpen>
|
||||
<Button as={Dropdown.Toggle}>Toggle</Button>
|
||||
@@ -57,20 +62,41 @@ export const DefaultOpen = {
|
||||
</Dropdown.Menu>
|
||||
</Dropdown>
|
||||
),
|
||||
args: { chromatic: { delay: 300 } },
|
||||
};
|
||||
|
||||
export const ControlledOpen = () => {
|
||||
const [openState, setOpenState] = useState(true);
|
||||
return (
|
||||
<Dropdown onSelect={(event) => console.log(event)} open={openState}>
|
||||
<Button as={Dropdown.Toggle} onClick={() => setOpenState(!openState)}>
|
||||
Toggle
|
||||
</Button>
|
||||
<Dropdown.Menu
|
||||
strategy="fixed"
|
||||
onClose={() => console.log("ONCLOSE CONTROLLED")}
|
||||
>
|
||||
export const ControlledOpen: Story = {
|
||||
render: () => {
|
||||
const [openState, setOpenState] = useState(true);
|
||||
return (
|
||||
<Dropdown onSelect={(event) => console.log(event)} open={openState}>
|
||||
<Button as={Dropdown.Toggle} onClick={() => setOpenState(!openState)}>
|
||||
Toggle
|
||||
</Button>
|
||||
<Dropdown.Menu
|
||||
strategy="fixed"
|
||||
onClose={() => console.log("ONCLOSE CONTROLLED")}
|
||||
>
|
||||
<Dropdown.Menu.GroupedList>
|
||||
<Dropdown.Menu.GroupedList.Heading>
|
||||
Systemer og oppslagsverk
|
||||
</Dropdown.Menu.GroupedList.Heading>
|
||||
<Dropdown.Menu.GroupedList.Item
|
||||
onClick={() => console.log("GroupedList.Item-click")}
|
||||
>
|
||||
Gosys
|
||||
</Dropdown.Menu.GroupedList.Item>
|
||||
</Dropdown.Menu.GroupedList>
|
||||
</Dropdown.Menu>
|
||||
</Dropdown>
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
export const Chromatic: Story = {
|
||||
render: () => (
|
||||
<Dropdown onSelect={(event) => console.log(event)} open>
|
||||
<Dropdown.Toggle>Toggle</Dropdown.Toggle>
|
||||
<Dropdown.Menu strategy="fixed">
|
||||
<Dropdown.Menu.GroupedList>
|
||||
<Dropdown.Menu.GroupedList.Heading>
|
||||
Systemer og oppslagsverk
|
||||
@@ -81,8 +107,18 @@ export const ControlledOpen = () => {
|
||||
Gosys
|
||||
</Dropdown.Menu.GroupedList.Item>
|
||||
</Dropdown.Menu.GroupedList>
|
||||
<Dropdown.Menu.Divider />
|
||||
<Dropdown.Menu.List>
|
||||
<Dropdown.Menu.List.Item onClick={() => console.log("Item-click")}>
|
||||
Gosys
|
||||
</Dropdown.Menu.List.Item>
|
||||
<Dropdown.Menu.List.Item>Psys</Dropdown.Menu.List.Item>
|
||||
<Dropdown.Menu.List.Item disabled>Infotrygd</Dropdown.Menu.List.Item>
|
||||
</Dropdown.Menu.List>
|
||||
</Dropdown.Menu>
|
||||
</Dropdown>
|
||||
);
|
||||
),
|
||||
parameters: {
|
||||
chromatic: { disable: false, delay: 300 },
|
||||
},
|
||||
};
|
||||
ControlledOpen.args = { chromatic: { delay: 300 } };
|
||||
@@ -1,5 +1,6 @@
|
||||
import cl from "clsx";
|
||||
import React, { forwardRef, useRef, useState } from "react";
|
||||
import React, { forwardRef, useRef } from "react";
|
||||
import { useControllableState } from "../util/hooks";
|
||||
import { OverridableComponent } from "../util/types";
|
||||
import ExpansionCardContent, {
|
||||
ExpansionCardContentProps,
|
||||
@@ -116,24 +117,24 @@ export const ExpansionCard = forwardRef<HTMLDivElement, ExpansionCardProps>(
|
||||
},
|
||||
ref,
|
||||
) => {
|
||||
const [_open, _setOpen] = useState(defaultOpen);
|
||||
|
||||
const shouldFade = useRef<boolean>(!(Boolean(open) || defaultOpen));
|
||||
|
||||
const handleOpen = () => {
|
||||
if (open === undefined) {
|
||||
const newOpen = !_open;
|
||||
_setOpen(newOpen);
|
||||
onToggle?.(newOpen);
|
||||
} else {
|
||||
onToggle?.(!open);
|
||||
}
|
||||
shouldFade.current = true;
|
||||
};
|
||||
const [_open, _setOpen] = useControllableState({
|
||||
value: open,
|
||||
onChange: (newValue) => {
|
||||
onToggle?.(newValue);
|
||||
shouldFade.current = true;
|
||||
},
|
||||
defaultValue: defaultOpen,
|
||||
});
|
||||
|
||||
return (
|
||||
<ExpansionCardContext.Provider
|
||||
value={{ open: open ?? _open, toggleOpen: handleOpen, size }}
|
||||
value={{
|
||||
open: open ?? _open,
|
||||
toggleOpen: () => _setOpen((x) => !x),
|
||||
size,
|
||||
}}
|
||||
>
|
||||
<section
|
||||
{...rest}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Meta } from "@storybook/react";
|
||||
import { Meta, StoryObj } from "@storybook/react";
|
||||
import React from "react";
|
||||
import { VStack } from "../../layout/stack";
|
||||
import { ErrorSummary } from "./ErrorSummary";
|
||||
|
||||
export default {
|
||||
@@ -18,9 +19,14 @@ export default {
|
||||
},
|
||||
},
|
||||
},
|
||||
} as Meta;
|
||||
parameters: {
|
||||
chromatic: { disable: true },
|
||||
},
|
||||
} satisfies Meta<typeof ErrorSummary>;
|
||||
|
||||
export const Default = {
|
||||
type Story = StoryObj<typeof ErrorSummary>;
|
||||
|
||||
export const Default: Story = {
|
||||
render: (props) => (
|
||||
<ErrorSummary
|
||||
heading="Feiloppsummering komponent"
|
||||
@@ -35,11 +41,41 @@ export const Default = {
|
||||
),
|
||||
};
|
||||
|
||||
export const Small = () => (
|
||||
<ErrorSummary heading="Feiloppsummering komponent" size="small">
|
||||
<ErrorSummary.Item href="#1">Checkbox må fylles ut</ErrorSummary.Item>
|
||||
<ErrorSummary.Item href="#2">
|
||||
Tekstfeltet må ha en godkjent e-mail
|
||||
</ErrorSummary.Item>
|
||||
</ErrorSummary>
|
||||
);
|
||||
export const Small: Story = {
|
||||
render: () => (
|
||||
<ErrorSummary heading="Feiloppsummering komponent" size="small">
|
||||
<ErrorSummary.Item href="#1">Checkbox må fylles ut</ErrorSummary.Item>
|
||||
<ErrorSummary.Item href="#2">
|
||||
Tekstfeltet må ha en godkjent e-mail
|
||||
</ErrorSummary.Item>
|
||||
</ErrorSummary>
|
||||
),
|
||||
};
|
||||
|
||||
export const Chromatic: Story = {
|
||||
render: () => (
|
||||
<VStack gap="4">
|
||||
<div>
|
||||
<h2>Default</h2>
|
||||
<ErrorSummary heading="Feiloppsummering komponent">
|
||||
<ErrorSummary.Item href="#1">Checkbox må fylles ut</ErrorSummary.Item>
|
||||
<ErrorSummary.Item href="#2">
|
||||
Tekstfeltet må ha en godkjent e-mail
|
||||
</ErrorSummary.Item>
|
||||
</ErrorSummary>
|
||||
</div>
|
||||
<div>
|
||||
<h2>Small</h2>
|
||||
<ErrorSummary heading="Feiloppsummering komponent" size="small">
|
||||
<ErrorSummary.Item href="#1">Checkbox må fylles ut</ErrorSummary.Item>
|
||||
<ErrorSummary.Item href="#2">
|
||||
Tekstfeltet må ha en godkjent e-mail
|
||||
</ErrorSummary.Item>
|
||||
</ErrorSummary>
|
||||
</div>
|
||||
</VStack>
|
||||
),
|
||||
parameters: {
|
||||
chromatic: { disable: false },
|
||||
},
|
||||
};
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Meta } from "@storybook/react";
|
||||
import { Meta, StoryObj } from "@storybook/react";
|
||||
import React from "react";
|
||||
import { VStack } from "../../layout/stack";
|
||||
import TextField from "../textfield/TextField";
|
||||
import { Fieldset } from "./index";
|
||||
|
||||
@@ -26,7 +27,12 @@ export default {
|
||||
type: "boolean",
|
||||
},
|
||||
},
|
||||
} as Meta;
|
||||
parameters: {
|
||||
chromatic: { disable: true },
|
||||
},
|
||||
} satisfies Meta<typeof Fieldset>;
|
||||
|
||||
type Story = StoryObj<typeof Fieldset>;
|
||||
|
||||
const content = (
|
||||
<>
|
||||
@@ -35,88 +41,117 @@ const content = (
|
||||
</>
|
||||
);
|
||||
|
||||
export const Default = {
|
||||
render: (props) => {
|
||||
return (
|
||||
<Fieldset legend="Mollit eiusmod" {...props}>
|
||||
{content}
|
||||
</Fieldset>
|
||||
);
|
||||
},
|
||||
const contentWithError = (
|
||||
<>
|
||||
<TextField label="Textfield label" hideLabel error="Må være fylt ut" />
|
||||
<TextField label="Textfield label" hideLabel />
|
||||
</>
|
||||
);
|
||||
|
||||
export const Default: Story = {
|
||||
args: {
|
||||
legend: "Mollit eiusmod",
|
||||
description:
|
||||
"Do ullamco amet mollit labore tempor minim cupidatat dolore voluptate velit irure.",
|
||||
errorPropagation: true,
|
||||
children: content,
|
||||
},
|
||||
};
|
||||
|
||||
export const Small = () => (
|
||||
<Fieldset
|
||||
size="small"
|
||||
legend="Mollit eiusmod"
|
||||
description="Do ullamco amet mollit labore tempor minim cupidatat dolore voluptate velit irure."
|
||||
>
|
||||
{content}
|
||||
</Fieldset>
|
||||
);
|
||||
export const Small: Story = {
|
||||
args: {
|
||||
legend: "Mollit eiusmod",
|
||||
description:
|
||||
"Do ullamco amet mollit labore tempor minim cupidatat dolore voluptate velit irure.",
|
||||
errorPropagation: true,
|
||||
children: content,
|
||||
size: "small",
|
||||
},
|
||||
};
|
||||
|
||||
export const Description = () => (
|
||||
<Fieldset
|
||||
legend="Mollit eiusmod"
|
||||
description="Esse cupidatat reprehenderit est culpa consectetur sit dolor esse."
|
||||
>
|
||||
<TextField
|
||||
label="Textfield label"
|
||||
description="Amet quis cillum incididunt "
|
||||
/>
|
||||
<TextField
|
||||
label="Textfield label"
|
||||
description="Enim et occaecat voluptate labore sit do exercitation laborum non "
|
||||
/>
|
||||
</Fieldset>
|
||||
);
|
||||
export const ErrorPropagation: Story = {
|
||||
args: {
|
||||
legend: "Mollit eiusmod",
|
||||
description:
|
||||
"Do ullamco amet mollit labore tempor minim cupidatat dolore voluptate velit irure.",
|
||||
errorPropagation: false,
|
||||
children: contentWithError,
|
||||
},
|
||||
};
|
||||
|
||||
export const ErrorPropagation = () => (
|
||||
<Fieldset
|
||||
legend="Mollit eiusmod"
|
||||
error="Fieldsett error"
|
||||
errorPropagation={false}
|
||||
>
|
||||
<TextField label="Textfield label" hideLabel error="Må være fylt ut" />
|
||||
<TextField label="Textfield label" hideLabel />
|
||||
</Fieldset>
|
||||
);
|
||||
export const Error: Story = {
|
||||
args: {
|
||||
legend: "Mollit eiusmod",
|
||||
description:
|
||||
"Do ullamco amet mollit labore tempor minim cupidatat dolore voluptate velit irure.",
|
||||
children: content,
|
||||
error: "Laborum officia nisi aliqua esse minim in amet.",
|
||||
},
|
||||
};
|
||||
|
||||
export const Error = () => (
|
||||
<div className="colgap">
|
||||
<Fieldset
|
||||
legend="Mollit eiusmod"
|
||||
error="Laborum officia nisi aliqua esse minim in amet."
|
||||
>
|
||||
{content}
|
||||
</Fieldset>
|
||||
<Fieldset
|
||||
size="small"
|
||||
legend="Mollit eiusmod"
|
||||
error="Laborum officia nisi aliqua esse minim in amet."
|
||||
>
|
||||
{content}
|
||||
</Fieldset>
|
||||
</div>
|
||||
);
|
||||
export const Disabled: Story = {
|
||||
args: {
|
||||
legend: "Mollit eiusmod",
|
||||
description:
|
||||
"Do ullamco amet mollit labore tempor minim cupidatat dolore voluptate velit irure.",
|
||||
children: content,
|
||||
disabled: true,
|
||||
},
|
||||
};
|
||||
|
||||
export const Disabled = () => (
|
||||
<div className="colgap">
|
||||
<Fieldset legend="Mollit eiusmod" disabled>
|
||||
{content}
|
||||
</Fieldset>
|
||||
<Fieldset size="small" legend="Mollit eiusmod" disabled>
|
||||
{content}
|
||||
</Fieldset>
|
||||
</div>
|
||||
);
|
||||
export const HideLegend: Story = {
|
||||
args: {
|
||||
legend: "Mollit eiusmod",
|
||||
description:
|
||||
"Do ullamco amet mollit labore tempor minim cupidatat dolore voluptate velit irure.",
|
||||
children: content,
|
||||
hideLegend: true,
|
||||
},
|
||||
};
|
||||
|
||||
export const HideLegend = () => (
|
||||
<Fieldset legend="Mollit eiusmod" hideLegend>
|
||||
{content}
|
||||
</Fieldset>
|
||||
);
|
||||
export const Chromatic: Story = {
|
||||
render: () => {
|
||||
return (
|
||||
<VStack gap="4">
|
||||
<div>
|
||||
<h2>Default</h2>
|
||||
{/* @ts-expect-error Args are Partial here */}
|
||||
<Fieldset {...Default.args} />
|
||||
</div>
|
||||
<div>
|
||||
<h2>Small</h2>
|
||||
{/* @ts-expect-error Args are Partial here */}
|
||||
<Fieldset {...Small.args} />
|
||||
</div>
|
||||
<div>
|
||||
<h2>ErrorPropagation</h2>
|
||||
{/* @ts-expect-error Args are Partial here */}
|
||||
<Fieldset {...ErrorPropagation.args} />
|
||||
</div>
|
||||
<div>
|
||||
<h2>Error</h2>
|
||||
{/* @ts-expect-error Args are Partial here */}
|
||||
<Fieldset {...Error.args} />
|
||||
</div>
|
||||
<div>
|
||||
<h2>Error small</h2>
|
||||
{/* @ts-expect-error Args are Partial here */}
|
||||
<Fieldset {...Error.args} size="small" />
|
||||
</div>
|
||||
<div>
|
||||
<h2>Disabled</h2>
|
||||
{/* @ts-expect-error Args are Partial here */}
|
||||
<Fieldset {...Disabled.args} />
|
||||
</div>
|
||||
<div>
|
||||
<h2>HideLegend</h2>
|
||||
{/* @ts-expect-error Args are Partial here */}
|
||||
<Fieldset {...HideLegend.args} />
|
||||
</div>
|
||||
</VStack>
|
||||
);
|
||||
},
|
||||
parameters: {
|
||||
chromatic: { disable: false },
|
||||
},
|
||||
};
|
||||
@@ -30,6 +30,7 @@ const Dropzone = forwardRef<HTMLInputElement, FileUploadDropzoneProps>(
|
||||
disabled,
|
||||
translations,
|
||||
onClick,
|
||||
id: buttonId,
|
||||
...rest
|
||||
} = props;
|
||||
|
||||
@@ -46,7 +47,10 @@ const Dropzone = forwardRef<HTMLInputElement, FileUploadDropzoneProps>(
|
||||
const _disabled = disabled ?? fileLimitReached;
|
||||
|
||||
const { inputProps, errorId, showErrorMsg, hasError, inputDescriptionId } =
|
||||
useFormField({ ...props, disabled: _disabled }, "fileUpload");
|
||||
useFormField(
|
||||
{ ...omit(props, ["id"]), disabled: _disabled },
|
||||
"fileUpload",
|
||||
);
|
||||
const {
|
||||
id: inputId,
|
||||
"aria-describedby": ariaDescribedby,
|
||||
@@ -131,6 +135,7 @@ const Dropzone = forwardRef<HTMLInputElement, FileUploadDropzoneProps>(
|
||||
<Button
|
||||
{...omit(rest, ["errorId"])}
|
||||
{...inputPropsRest}
|
||||
id={buttonId}
|
||||
aria-describedby={cl(labelId, ariaDescribedby)}
|
||||
className="navds-dropzone__area-button"
|
||||
type="button"
|
||||
|
||||
@@ -49,6 +49,7 @@ export const Default = (props) => {
|
||||
</RadioGroup>
|
||||
);
|
||||
};
|
||||
|
||||
Default.args = {
|
||||
controlled: false,
|
||||
error: false,
|
||||
|
||||
@@ -85,7 +85,7 @@ export const Switch = forwardRef<HTMLInputElement, SwitchProps>(
|
||||
...rest
|
||||
} = props;
|
||||
|
||||
const [checked, setChecked] = useState(
|
||||
const [_checked, setChecked] = useState(
|
||||
defaultChecked ?? checkedProp ?? false,
|
||||
);
|
||||
|
||||
@@ -93,6 +93,8 @@ export const Switch = forwardRef<HTMLInputElement, SwitchProps>(
|
||||
checkedProp !== undefined && setChecked(checkedProp);
|
||||
}, [checkedProp]);
|
||||
|
||||
const checked = checkedProp ?? _checked;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cl(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Meta } from "@storybook/react";
|
||||
import { Meta, StoryObj } from "@storybook/react";
|
||||
import React from "react";
|
||||
import { VStack } from "../../layout/stack";
|
||||
import Switch from "./Switch";
|
||||
|
||||
export default {
|
||||
@@ -31,70 +32,59 @@ export default {
|
||||
type: "boolean",
|
||||
},
|
||||
},
|
||||
} as Meta;
|
||||
|
||||
export const Default = {
|
||||
render: (props) => {
|
||||
return <Switch {...props}>Label text</Switch>;
|
||||
parameters: {
|
||||
chromatic: { disable: true },
|
||||
},
|
||||
} satisfies Meta<typeof Switch>;
|
||||
|
||||
type Story = StoryObj<typeof Switch>;
|
||||
|
||||
export const Default: Story = {
|
||||
args: {
|
||||
position: "right",
|
||||
children: "Label text",
|
||||
},
|
||||
};
|
||||
|
||||
export const Small = () => {
|
||||
return (
|
||||
<div className="colgap">
|
||||
<Switch size="small">Label text</Switch>
|
||||
<Switch size="small" position="right">
|
||||
Label text
|
||||
</Switch>
|
||||
</div>
|
||||
);
|
||||
export const Small: Story = {
|
||||
args: {
|
||||
children: "Label text",
|
||||
size: "small",
|
||||
},
|
||||
};
|
||||
|
||||
export const Description = () => {
|
||||
return (
|
||||
<div className="colgap">
|
||||
<Switch size="small" description="Cillum sint exercitation ut cillum.">
|
||||
Label text
|
||||
</Switch>
|
||||
<Switch
|
||||
size="small"
|
||||
position="right"
|
||||
description="Cillum sint exercitation ut cillum."
|
||||
>
|
||||
Label text
|
||||
</Switch>
|
||||
</div>
|
||||
);
|
||||
export const Description: Story = {
|
||||
args: {
|
||||
children: "Label text",
|
||||
description: "Cillum sint exercitation ut cillum.",
|
||||
},
|
||||
};
|
||||
|
||||
export const Loading = () => {
|
||||
return (
|
||||
<div className="colgap">
|
||||
export const Loading: Story = {
|
||||
render: () => {
|
||||
return (
|
||||
<div className="colgap">
|
||||
<Switch loading>Label text</Switch>
|
||||
<div className="colgap">
|
||||
<Switch loading>Label text</Switch>
|
||||
|
||||
<Switch checked loading>
|
||||
Label text
|
||||
</Switch>
|
||||
<Switch checked loading>
|
||||
Label text
|
||||
</Switch>
|
||||
</div>
|
||||
<div className="colgap">
|
||||
<Switch loading size="small">
|
||||
Label text
|
||||
</Switch>
|
||||
<Switch checked loading size="small">
|
||||
Label text
|
||||
</Switch>
|
||||
</div>
|
||||
</div>
|
||||
<div className="colgap">
|
||||
<Switch loading size="small">
|
||||
Label text
|
||||
</Switch>
|
||||
<Switch checked loading size="small">
|
||||
Label text
|
||||
</Switch>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
export const Disabled = () => {
|
||||
return (
|
||||
export const Disabled: Story = {
|
||||
render: () => (
|
||||
<div className="colgap">
|
||||
<Switch disabled>Label text</Switch>
|
||||
|
||||
@@ -102,11 +92,11 @@ export const Disabled = () => {
|
||||
Label text
|
||||
</Switch>
|
||||
</div>
|
||||
);
|
||||
),
|
||||
};
|
||||
|
||||
export const HideLabel = () => {
|
||||
return (
|
||||
export const HideLabel: Story = {
|
||||
render: () => (
|
||||
<div className="colgap">
|
||||
<Switch hideLabel>Label text</Switch>
|
||||
|
||||
@@ -114,11 +104,11 @@ export const HideLabel = () => {
|
||||
Label text
|
||||
</Switch>
|
||||
</div>
|
||||
);
|
||||
),
|
||||
};
|
||||
|
||||
export const Readonly = () => {
|
||||
return (
|
||||
export const Readonly: Story = {
|
||||
render: () => (
|
||||
<div className="colgap">
|
||||
<Switch description="Slår av alle notifikasjoner" readOnly>
|
||||
Notifikasjoner
|
||||
@@ -128,5 +118,54 @@ export const Readonly = () => {
|
||||
Notifikasjoner
|
||||
</Switch>
|
||||
</div>
|
||||
);
|
||||
),
|
||||
};
|
||||
|
||||
export const Chromatic: Story = {
|
||||
render: () => (
|
||||
<VStack gap="4" align="start">
|
||||
<div>
|
||||
<h2>Default</h2>
|
||||
{/* @ts-expect-error Args are Partial here */}
|
||||
<Switch {...Default.args} />
|
||||
</div>
|
||||
<div>
|
||||
<h2>Small</h2>
|
||||
{/* @ts-expect-error Args are Partial here */}
|
||||
<Switch {...Small.args} position="left" />
|
||||
{/* @ts-expect-error Args are Partial here */}
|
||||
<Switch {...Small.args} position="right" />
|
||||
</div>
|
||||
<div>
|
||||
<h2>Description</h2>
|
||||
{/* @ts-expect-error Args are Partial here */}
|
||||
<Switch {...Description.args} position="left" />
|
||||
{/* @ts-expect-error Args are Partial here */}
|
||||
<Switch {...Description.args} position="right" />
|
||||
</div>
|
||||
<div>
|
||||
<h2>Loading</h2>
|
||||
{/* @ts-expect-error Args are Partial here */}
|
||||
<Loading.render />
|
||||
</div>
|
||||
<div>
|
||||
<h2>Disabled</h2>
|
||||
{/* @ts-expect-error Args are Partial here */}
|
||||
<Disabled.render />
|
||||
</div>
|
||||
<div>
|
||||
<h2>HideLabel</h2>
|
||||
{/* @ts-expect-error Args are Partial here */}
|
||||
<HideLabel.render />
|
||||
</div>
|
||||
<div>
|
||||
<h2>Readonly</h2>
|
||||
{/* @ts-expect-error Args are Partial here */}
|
||||
<Readonly.render />
|
||||
</div>
|
||||
</VStack>
|
||||
),
|
||||
parameters: {
|
||||
chromatic: { disable: false },
|
||||
},
|
||||
};
|
||||
@@ -1,65 +1,91 @@
|
||||
import { Meta, StoryFn } from "@storybook/react";
|
||||
import React, { useState } from "react";
|
||||
import { Meta, StoryObj } from "@storybook/react";
|
||||
import { fn } from "@storybook/test";
|
||||
import React from "react";
|
||||
import { ReadMore } from ".";
|
||||
import { VStack } from "../layout/stack";
|
||||
|
||||
const meta: Meta<typeof ReadMore> = {
|
||||
export default {
|
||||
title: "ds-react/ReadMore",
|
||||
component: ReadMore,
|
||||
};
|
||||
export default meta;
|
||||
parameters: {
|
||||
chromatic: { disable: true },
|
||||
},
|
||||
} satisfies Meta<typeof ReadMore>;
|
||||
|
||||
export const Default: StoryFn<{
|
||||
controlled: boolean;
|
||||
size: "medium" | "small";
|
||||
defaultOpen: boolean;
|
||||
}> = (props) => {
|
||||
const [state, setState] = useState(false);
|
||||
type Story = StoryObj<typeof ReadMore>;
|
||||
|
||||
return (
|
||||
<ReadMore
|
||||
open={props.controlled ? state : undefined}
|
||||
onClick={() => setState((x) => !x)}
|
||||
header="Grunnen til at vi spør om dette og i tillegg ber om vedlegg"
|
||||
size={props.size}
|
||||
onOpenChange={console.log}
|
||||
defaultOpen={props.defaultOpen}
|
||||
>
|
||||
<div style={{ maxWidth: 300 }}>
|
||||
Lorem ipsum dolor sit amet consectetur adipisicing elit. Mollitia,
|
||||
tempore corporis exercitationem minus dignissimos eius aspernatur fugiat
|
||||
iusto.
|
||||
</div>
|
||||
</ReadMore>
|
||||
);
|
||||
};
|
||||
Default.args = {
|
||||
controlled: false,
|
||||
size: "medium",
|
||||
defaultOpen: false,
|
||||
};
|
||||
Default.argTypes = {
|
||||
size: {
|
||||
options: ["medium", "small"],
|
||||
control: { type: "radio" },
|
||||
const Content = (
|
||||
<div style={{ maxWidth: 300 }}>
|
||||
Lorem ipsum dolor sit amet consectetur adipisicing elit. Mollitia, tempore
|
||||
corporis exercitationem minus dignissimos eius aspernatur fugiat iusto.
|
||||
</div>
|
||||
);
|
||||
|
||||
export const Default: Story = {
|
||||
args: {
|
||||
size: "medium",
|
||||
defaultOpen: false,
|
||||
onOpenChange: fn(),
|
||||
children: Content,
|
||||
header: "Grunnen til at vi spør om dette og i tillegg ber om vedlegg",
|
||||
},
|
||||
argTypes: {
|
||||
size: {
|
||||
options: ["medium", "small"],
|
||||
control: { type: "radio" },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const Small = () => (
|
||||
<ReadMore
|
||||
header="Grunnen til at vi spør om dette og i tillegg ber om vedlegg"
|
||||
size="small"
|
||||
>
|
||||
Command station, this is ST 321. Code Clearance Blue. We're starting
|
||||
our approach. Deactivate the security shield.
|
||||
</ReadMore>
|
||||
);
|
||||
export const Small: Story = {
|
||||
args: {
|
||||
...Default.args,
|
||||
size: "small",
|
||||
},
|
||||
};
|
||||
|
||||
export const Open = () => (
|
||||
<ReadMore
|
||||
header="Grunnen til at vi spør om dette og i tillegg ber om vedlegg"
|
||||
defaultOpen
|
||||
>
|
||||
Command station, this is ST 321. Code Clearance Blue. We're starting
|
||||
our approach. Deactivate the security shield.
|
||||
</ReadMore>
|
||||
);
|
||||
export const DefaultOpen: Story = {
|
||||
args: {
|
||||
...Default.args,
|
||||
defaultOpen: true,
|
||||
},
|
||||
};
|
||||
|
||||
export const Open: Story = {
|
||||
args: {
|
||||
...Default.args,
|
||||
open: true,
|
||||
},
|
||||
};
|
||||
|
||||
export const Chromatic: Story = {
|
||||
render: () => {
|
||||
return (
|
||||
<VStack gap="4">
|
||||
<div>
|
||||
<h2>Default</h2>
|
||||
{/* @ts-expect-error Args are partial, leading to required prop mismatch */}
|
||||
<ReadMore {...Default.args} />
|
||||
</div>
|
||||
<div>
|
||||
<h2>Small</h2>
|
||||
{/* @ts-expect-error Args are partial, leading to required prop mismatch */}
|
||||
<ReadMore {...Small.args} />
|
||||
</div>
|
||||
<div>
|
||||
<h2>DefaultOpen</h2>
|
||||
{/* @ts-expect-error Args are partial, leading to required prop mismatch */}
|
||||
<ReadMore {...DefaultOpen.args} />
|
||||
</div>
|
||||
<div>
|
||||
<h2>Controlled open</h2>
|
||||
{/* @ts-expect-error Args are partial, leading to required prop mismatch */}
|
||||
<ReadMore {...Open.args} />
|
||||
</div>
|
||||
</VStack>
|
||||
);
|
||||
},
|
||||
parameters: {
|
||||
chromatic: { disable: false },
|
||||
},
|
||||
};
|
||||
@@ -1,5 +1,9 @@
|
||||
# @navikt/ds-tailwind
|
||||
|
||||
## 6.3.4
|
||||
|
||||
## 6.3.3
|
||||
|
||||
## 6.3.2
|
||||
|
||||
## 6.3.1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/ds-tailwind",
|
||||
"version": "6.3.2",
|
||||
"version": "6.3.4",
|
||||
"description": "Tailwind config based on @navikt/ds-tokens",
|
||||
"author": "Aksel | NAV designsystem team",
|
||||
"keywords": [
|
||||
@@ -25,7 +25,7 @@
|
||||
"directory": "@navikt/core/tailwind"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@navikt/ds-tokens": "^6.3.2",
|
||||
"@navikt/ds-tokens": "^6.3.4",
|
||||
"color": "4.2.3",
|
||||
"lodash": "^4.17.21",
|
||||
"tailwindcss": "^3.3.3",
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# @navikt/ds-tokens
|
||||
|
||||
## 6.3.4
|
||||
|
||||
## 6.3.3
|
||||
|
||||
## 6.3.2
|
||||
|
||||
## 6.3.1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/ds-tokens",
|
||||
"version": "6.3.2",
|
||||
"version": "6.3.4",
|
||||
"description": "Design-tokens for NAV designsystem",
|
||||
"author": "Aksel | NAV designsystem team",
|
||||
"keywords": [
|
||||
|
||||
+11
-1
@@ -4,10 +4,20 @@
|
||||
|
||||
### @navikt/ds-css
|
||||
|
||||
- FileUpload: Ny komponent `FileUpload` for å håndtere opplasting av filer, Dropzone og fil-visning ([#2504](https://github.com/navikt/aksel/pull/2504))
|
||||
- ReadMore: Padding-right på button er bumpet noen px ([#2806](https://github.com/navikt/aksel/pull/2806))
|
||||
|
||||
* FileUpload: Ny komponent `FileUpload` for å håndtere opplasting av filer, Dropzone og fil-visning ([#2504](https://github.com/navikt/aksel/pull/2504))
|
||||
|
||||
### @navikt/ds-react
|
||||
|
||||
- Switch: Fikset edgecase der checked Switch var visuelt unchecked ([#2810](https://github.com/navikt/aksel/pull/2810))
|
||||
|
||||
- FileUpload.Dropzone: id prop settes på button ([#2817](https://github.com/navikt/aksel/pull/2817))
|
||||
|
||||
* FileUpload.Dropzone: Fiks feil med duplisert id ([#2805](https://github.com/navikt/aksel/pull/2805))
|
||||
|
||||
* useDatePicker: `isInvalid`-key i onValidate var hadde flipper boolean i noen tilfeller ([#2809](https://github.com/navikt/aksel/pull/2809))
|
||||
|
||||
- FileUpload: Fiks feil ved import av json ([#2803](https://github.com/navikt/aksel/pull/2803))
|
||||
|
||||
* FileUpload: Disabled dropzone stopper opplasting ([#2798](https://github.com/navikt/aksel/pull/2798))
|
||||
|
||||
@@ -4,8 +4,9 @@ ENV NODE_ENV production
|
||||
|
||||
WORKDIR /app
|
||||
COPY aksel.nav.no/website/.next/standalone ./
|
||||
COPY aksel.nav.no/website/config/next-logger.config.js ./
|
||||
COPY aksel.nav.no/website/next-logger.config.js ./
|
||||
|
||||
ENV NODE_ENV=production
|
||||
ENV NODE_OPTIONS '-r next-logger'
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
@@ -21,6 +21,9 @@ spec:
|
||||
outbound:
|
||||
external:
|
||||
- host: api.sanity.io
|
||||
- host: api.slack.com
|
||||
- host: slack.com
|
||||
- host: wss-primary.slack.com
|
||||
- host: hnbe3yhs.api.sanity.io
|
||||
- host: apicdn.sanity.io
|
||||
- host: hnbe3yhs.apicdn.sanity.io
|
||||
|
||||
@@ -25,6 +25,9 @@ spec:
|
||||
outbound:
|
||||
external:
|
||||
- host: api.sanity.io
|
||||
- host: api.slack.com
|
||||
- host: slack.com
|
||||
- host: wss-primary.slack.com
|
||||
- host: hnbe3yhs.api.sanity.io
|
||||
- host: apicdn.sanity.io
|
||||
- host: hnbe3yhs.apicdn.sanity.io
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
"playroom"
|
||||
],
|
||||
"dependencies": {
|
||||
"@navikt/aksel-icons": "^6.3.2",
|
||||
"@navikt/ds-css": "^6.3.2",
|
||||
"@navikt/ds-react": "^6.3.2",
|
||||
"@navikt/ds-tailwind": "^6.3.2",
|
||||
"@navikt/ds-tokens": "^6.3.2"
|
||||
"@navikt/aksel-icons": "^6.3.4",
|
||||
"@navikt/ds-css": "^6.3.4",
|
||||
"@navikt/ds-react": "^6.3.4",
|
||||
"@navikt/ds-tailwind": "^6.3.4",
|
||||
"@navikt/ds-tokens": "^6.3.4"
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
"babel-loader": "^9.1.3",
|
||||
"babel-plugin-preval": "^5.1.0",
|
||||
"css-loader": "^6.8.1",
|
||||
"playroom": "^0.32.1",
|
||||
"playroom": "^0.37.0",
|
||||
"style-loader": "^3.3.3"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -13,7 +13,7 @@ module.exports = {
|
||||
title: "Aksel Sandbox",
|
||||
snippets: path.resolve("./src/snippets.ts"),
|
||||
widths: [320, 480, 768, 1024, 1280, 1440],
|
||||
defaultWidths: [320, 1280], // will be supported if this PR is merged: https://github.com/seek-oss/playroom/pull/302
|
||||
defaultVisibleWidths: [320, 1280],
|
||||
port: 9000,
|
||||
frameComponent: path.resolve("./src/FrameComponent.tsx"),
|
||||
useScope: path.resolve("./src/useScope.tsx"),
|
||||
|
||||
@@ -99,6 +99,14 @@ const config: StorybookConfig = {
|
||||
__dirname,
|
||||
"../components/layout/",
|
||||
);
|
||||
sbConfig.resolve.alias["@/auth"] = resolve(
|
||||
__dirname,
|
||||
"../components/auth/",
|
||||
);
|
||||
sbConfig.resolve.alias["@/slack"] = resolve(
|
||||
__dirname,
|
||||
"../components/utils/slack/index.ts",
|
||||
);
|
||||
sbConfig.resolve.alias["@/assets"] = resolve(
|
||||
__dirname,
|
||||
"../components/assets/",
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { NextApiRequest, NextApiResponse } from "next/types";
|
||||
|
||||
export type ApiHandler = (
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse,
|
||||
) => Promise<unknown> | unknown;
|
||||
|
||||
export type AuthUser = {
|
||||
name: "name";
|
||||
email: "email";
|
||||
};
|
||||
|
||||
export const AuthApiErrorReturn = {
|
||||
"Access denied": "Access denied",
|
||||
} as const;
|
||||
|
||||
export type AuthApiErrorReturn = {
|
||||
ok: false;
|
||||
error: (typeof AuthApiErrorReturn)[keyof typeof AuthApiErrorReturn];
|
||||
};
|
||||
|
||||
type LoggedInT = {
|
||||
signedIn: true;
|
||||
user: AuthUser;
|
||||
};
|
||||
|
||||
type NotLoggedInT = {
|
||||
signedIn: false;
|
||||
user: null;
|
||||
};
|
||||
|
||||
export type UserStateT = LoggedInT | NotLoggedInT;
|
||||
@@ -1,11 +1,6 @@
|
||||
import { NextApiRequest, NextApiResponse } from "next/types";
|
||||
import { logger } from "@navikt/next-logger";
|
||||
import { ApiHandler } from "@/auth/auth.types";
|
||||
import { validateWonderwallToken } from "@/auth/validateWonderwall";
|
||||
import { logger } from "../../config/logger";
|
||||
|
||||
type ApiHandler = (
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse,
|
||||
) => Promise<unknown> | unknown;
|
||||
|
||||
/**
|
||||
* Used to authenticate Next.JS pages. Assumes application is behind
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import { NextApiRequest } from "next/types";
|
||||
import { logger } from "@navikt/next-logger";
|
||||
import { AuthUser } from "@/auth/auth.types";
|
||||
|
||||
export function getAuthUser(headers: NextApiRequest["headers"]): {
|
||||
name: string | null;
|
||||
email: string | null;
|
||||
} {
|
||||
export function getAuthUser(
|
||||
headers: NextApiRequest["headers"],
|
||||
): AuthUser | null {
|
||||
const token = getToken(headers);
|
||||
if (!token) {
|
||||
return {
|
||||
name: null,
|
||||
email: null,
|
||||
};
|
||||
return null;
|
||||
}
|
||||
|
||||
const jwt = JSON.parse(
|
||||
@@ -26,7 +24,12 @@ export const fakeToken =
|
||||
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImtpZCI6IjlHbW55RlBraGMzaE91UjIybXZTdmduTG83WSJ9.eyJhdWQiOiJmYWtlLWF1ZCIsImlzcyI6Imh0dHBzOi8vbG9naW4ubWljcm9zb2Z0b25saW5lLmNvbS85NjZhYzU3Mi1mNWI3LTRiYmUtYWE4OC1jNzY0MTljMGY4NTEvdjIuMCIsImlhdCI6MTY5ODQxMTU0NiwibmJmIjoxNjk4NDExNTQ2LCJleHAiOjE2OTg0MTY1MjYsImFpbyI6ImZha2UtYWlvIiwiYXpwIjoiZmFrZS1henAiLCJhenBhY3IiOiIyIiwiZ3JvdXBzIjpbImZha2UtZ3JvdXAiXSwibmFtZSI6IkZha2UgVG9rZW5lbnNzb24iLCJvaWQiOiJmYWtlLW9pZCIsInByZWZlcnJlZF91c2VybmFtZSI6ImZha2UtbG9uZy1lbWFpbC1hdEBleGFtcGxlLm5vIiwicmgiOiJmYWtlLXJoLiIsInNjcCI6ImRlZmF1bHRhY2Nlc3MiLCJzdWIiOiJmYWtlLXN1YiIsInRpZCI6ImZha2UtdGlkIiwidXRpIjoiekY4R0VGemhfRTZya3gtYzNnNFNBQSIsInZlciI6IjIuMCIsIk5BVmlkZW50IjoiWjk5MjM4OSIsImF6cF9uYW1lIjoiZGV2LWdjcDpmYWtlLXRlYW06aGVsc2VzamVray1ib3QifQ.OOP_Q0ZcUI6jQzM1UON9mA8d8BU_GhioQ5OLuepwebg";
|
||||
|
||||
export function getToken(headers: NextApiRequest["headers"]) {
|
||||
if (process.env.NODE_ENV !== "production") return fakeToken;
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
logger.info(
|
||||
"Is running locally or in demo, using local fake token for Authenticated user-requests",
|
||||
);
|
||||
return fakeToken;
|
||||
}
|
||||
|
||||
return headers.authorization?.replace("Bearer ", "") ?? null;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { NextApiRequest } from "next/types";
|
||||
import { logger } from "@navikt/next-logger";
|
||||
import { UserStateT } from "@/auth/auth.types";
|
||||
import { getAuthUser } from "@/auth/getAuthUser";
|
||||
import { validateWonderwallToken } from "@/auth/validateWonderwall";
|
||||
|
||||
export async function getAuthUserState(
|
||||
headers: NextApiRequest["headers"],
|
||||
): Promise<UserStateT> {
|
||||
const isSignedIn = await validateWonderwallToken(headers);
|
||||
|
||||
if (!isSignedIn) {
|
||||
return {
|
||||
signedIn: false,
|
||||
user: null,
|
||||
};
|
||||
}
|
||||
|
||||
const user = getAuthUser(headers);
|
||||
|
||||
if (!user) {
|
||||
logger.error(
|
||||
"User is signed in, but no user was found in the token. This should be impossible!",
|
||||
);
|
||||
return {
|
||||
signedIn: false,
|
||||
user: null,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
signedIn: true,
|
||||
user,
|
||||
};
|
||||
}
|
||||
@@ -1,16 +1,22 @@
|
||||
import { useRouter } from "next/router";
|
||||
|
||||
export const useAuth = () => {
|
||||
const router = useRouter();
|
||||
export const useAuth = (addRedirect?: boolean) => {
|
||||
const { push, asPath } = useRouter();
|
||||
|
||||
const login = async () => {
|
||||
router.push(`/oauth2/login?redirect=${router.asPath}`, undefined, {
|
||||
shallow: true,
|
||||
});
|
||||
push(
|
||||
`/oauth2/login?redirect=${asPath.split("#")[0]}${
|
||||
addRedirect ? encodeURIComponent("#scrollToFeedback") : ""
|
||||
}`,
|
||||
undefined,
|
||||
{
|
||||
shallow: true,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const logout = async () => {
|
||||
router.push(`/oauth2/logout?redirect=${router.asPath}`, undefined, {
|
||||
push(`/oauth2/logout?redirect=${asPath}`, undefined, {
|
||||
shallow: true,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { NextApiRequest } from "next/types";
|
||||
import { logger } from "@navikt/next-logger";
|
||||
import { getToken, validateAzureToken } from "@navikt/oasis";
|
||||
import { logger } from "../../config/logger";
|
||||
|
||||
/**
|
||||
* Validates the wonderwall token according to nais.io. Should only actually redirect if the token has expired.
|
||||
@@ -29,6 +29,10 @@ export async function validateWonderwallToken(
|
||||
{ cause: validationResult.error },
|
||||
),
|
||||
);
|
||||
} else {
|
||||
logger.error(
|
||||
`JWT token has expired (cause: ${validationResult.errorType} ${validationResult.error}`,
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -6,4 +6,5 @@ export enum AmplitudeEvents {
|
||||
"feedbackinteraksjon" = "feedbackinteraksjon",
|
||||
"søk" = "søk",
|
||||
"link" = "link",
|
||||
"slackfeedback" = "slackfeedback",
|
||||
}
|
||||
@@ -61,7 +61,7 @@ const useAmplitudeInit = () => {
|
||||
.forEach(([event, eventData]) => amplitude.track(event, eventData)),
|
||||
)
|
||||
.catch(async () => {
|
||||
const { logger } = await import("../../config/logger");
|
||||
const { logger } = await import("@navikt/next-logger");
|
||||
logger.error("Failed logging batched events");
|
||||
});
|
||||
};
|
||||
|
||||
@@ -22,7 +22,7 @@ describe("Utils test", () => {
|
||||
expect(capitalize(str4)).toEqual("Teststr");
|
||||
});
|
||||
|
||||
test("dateStr", async () => {
|
||||
test("dateStr", { retry: 10, timeout: 8000 }, async () => {
|
||||
const date = "2022-06-09T11:05:48Z";
|
||||
const date2 = "2021-03-02T12:05:48Z";
|
||||
|
||||
|
||||
@@ -2,7 +2,11 @@ export const dateStr = async (date: string) => {
|
||||
if (!date) {
|
||||
return "";
|
||||
}
|
||||
const { format } = await import("date-fns");
|
||||
const { nb } = await import("date-fns/locale");
|
||||
|
||||
const [{ format }, { nb }] = await Promise.all([
|
||||
import("date-fns"),
|
||||
import("date-fns/locale"),
|
||||
]);
|
||||
|
||||
return format(new Date(date), "d. MMMM yyy", { locale: nb });
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
import { expect, test } from "vitest";
|
||||
import { findUserByEmail } from "../find-user";
|
||||
|
||||
test("findUserByEmail returns user when user with given email exists", () => {
|
||||
const members = [
|
||||
{ id: "test_id", email: "test1@example.com" },
|
||||
{ id: "test_id", email: "test2@example.com" },
|
||||
{ id: "test_id", email: "test3@example.com" },
|
||||
];
|
||||
|
||||
const result = findUserByEmail("test2@example.com", members);
|
||||
expect(result).toEqual(members[1]);
|
||||
});
|
||||
|
||||
test("findUserByEmail returns undefined when user with given email does not exist", () => {
|
||||
const members = [
|
||||
{ id: "test_id", email: "test1@example.com" },
|
||||
{ id: "test_id", email: "test2@example.com" },
|
||||
{ id: "test_id", email: "test3@example.com" },
|
||||
];
|
||||
|
||||
const result = findUserByEmail("nonexistent@example.com", members);
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
|
||||
test("findUserByEmail returns undefined member contains no email-key", () => {
|
||||
const members = [{}, {}, {}];
|
||||
|
||||
const result = findUserByEmail("nonexistent@example.com", members);
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
|
||||
test("findUserByEmail is case insensitive", () => {
|
||||
const members = [
|
||||
{ id: "test_id", email: "test1@example.com" },
|
||||
{ id: "test_id", email: "test2@example.com" },
|
||||
{ id: "test_id", email: "test3@example.com" },
|
||||
];
|
||||
|
||||
const result = findUserByEmail("TEST2@EXAMPLE.COM", members);
|
||||
expect(result).toEqual(members[1]);
|
||||
});
|
||||
@@ -0,0 +1,94 @@
|
||||
import { UsersListResponse, WebClient } from "@slack/web-api";
|
||||
import NodeCache from "node-cache";
|
||||
import {
|
||||
FetchSlackMembersError,
|
||||
FetchSlackMembersSuccess,
|
||||
SanitizedUser,
|
||||
} from "./slack.types";
|
||||
|
||||
const cache = new NodeCache();
|
||||
const CACHE_KEY = "fetchslackMembers";
|
||||
|
||||
export async function fetchSlackMembers(): Promise<
|
||||
FetchSlackMembersSuccess | FetchSlackMembersError
|
||||
> {
|
||||
const slackMembers: FetchSlackMembersSuccess["members"] | undefined =
|
||||
cache.get(CACHE_KEY);
|
||||
|
||||
if (slackMembers) {
|
||||
return {
|
||||
ok: true,
|
||||
members: slackMembers,
|
||||
};
|
||||
}
|
||||
|
||||
const client = new WebClient(process.env.SLACK_BOT_TOKEN);
|
||||
|
||||
const pagination: {
|
||||
limit: number;
|
||||
cursor: string | undefined;
|
||||
continue: boolean;
|
||||
} = {
|
||||
limit: 900,
|
||||
cursor: undefined,
|
||||
continue: true,
|
||||
};
|
||||
|
||||
let members: Exclude<UsersListResponse["members"], undefined> = [];
|
||||
let error: string | undefined = undefined;
|
||||
|
||||
while (pagination.continue) {
|
||||
const users = await client.users.list({
|
||||
cursor: pagination.cursor,
|
||||
limit: pagination.limit,
|
||||
});
|
||||
|
||||
if (users.ok && users.members) {
|
||||
members = members.concat(users.members);
|
||||
} else {
|
||||
pagination.continue = false;
|
||||
error = users.error;
|
||||
break;
|
||||
}
|
||||
|
||||
if (
|
||||
users.response_metadata?.next_cursor &&
|
||||
users.response_metadata?.next_cursor !== ""
|
||||
) {
|
||||
pagination.cursor = users.response_metadata.next_cursor;
|
||||
} else {
|
||||
pagination.continue = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return {
|
||||
ok: false,
|
||||
error: error ?? "Error when paginating slack-users",
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets filter out som unwanted users to simplify the list
|
||||
*/
|
||||
const subset_members = members
|
||||
.filter((m) => !m.is_bot)
|
||||
.filter((m) => !m.deleted)
|
||||
.filter((m) => m.profile?.email)
|
||||
.filter((m) => m.id)
|
||||
.map((m) => ({
|
||||
id: m.id,
|
||||
email: m.profile?.email,
|
||||
})) as SanitizedUser[]; // TODO: perhaps not needed with newer TS version
|
||||
|
||||
if (subset_members.length === 0) {
|
||||
return { ok: false, error: "No members found" };
|
||||
}
|
||||
|
||||
cache.set(CACHE_KEY, subset_members, 60 * 60 * 24);
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
members: subset_members,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { SanitizedUser } from "./slack.types";
|
||||
|
||||
export function findUserByEmail(
|
||||
email: string,
|
||||
members: Partial<SanitizedUser>[],
|
||||
) {
|
||||
return members?.find((m) => m.email?.toLowerCase() === email.toLowerCase());
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export { fetchSlackMembers } from "./fetch-members";
|
||||
export { findUserByEmail } from "./find-user";
|
||||
export {
|
||||
SlackFeedbackError,
|
||||
type SlackFeedbackResponse,
|
||||
type SlackFeedbackErrorT,
|
||||
} from "./slack.types";
|
||||
@@ -0,0 +1,57 @@
|
||||
import { AuthApiErrorReturn } from "@/auth/auth.types";
|
||||
|
||||
export type SlackFeedbackInput = {
|
||||
/**
|
||||
* Feedback message
|
||||
*/
|
||||
feedback: string;
|
||||
/**
|
||||
* If user wants to be anonymous
|
||||
*/
|
||||
anon: boolean;
|
||||
/**
|
||||
* Sanity-document id for article feedback is about
|
||||
*/
|
||||
document_id: string;
|
||||
};
|
||||
|
||||
type SlackFeedbackOkResponse = {
|
||||
ok: true;
|
||||
};
|
||||
|
||||
export const SlackFeedbackError = {
|
||||
InvalidBody: "InvalidBody",
|
||||
InvalidUser: "InvalidUser",
|
||||
InvalidId: "InvalidId",
|
||||
NoEditors: "NoEditors",
|
||||
NoSlackUsers: "NoSlackUsers",
|
||||
PostMessageError: "PostMessageError",
|
||||
} as const;
|
||||
|
||||
export type SlackFeedbackErrorT =
|
||||
(typeof SlackFeedbackError)[keyof typeof SlackFeedbackError];
|
||||
|
||||
type SlackFeedbackErrorResponse = {
|
||||
ok: false;
|
||||
error: SlackFeedbackErrorT;
|
||||
};
|
||||
|
||||
export type SlackFeedbackResponse =
|
||||
| SlackFeedbackOkResponse
|
||||
| SlackFeedbackErrorResponse
|
||||
| AuthApiErrorReturn;
|
||||
|
||||
export type SanitizedUser = {
|
||||
id: string;
|
||||
email: string;
|
||||
};
|
||||
|
||||
export type FetchSlackMembersSuccess = {
|
||||
ok: true;
|
||||
members: SanitizedUser[];
|
||||
};
|
||||
|
||||
export type FetchSlackMembersError = {
|
||||
ok: false;
|
||||
error: string;
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
.responsive {
|
||||
font-size: 4rem;
|
||||
}
|
||||
|
||||
.responsive_square {
|
||||
position: absolute;
|
||||
transform: translate(1rem, -1.1rem);
|
||||
}
|
||||
|
||||
.responsive_inbox {
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.responsive {
|
||||
font-size: 3rem;
|
||||
}
|
||||
|
||||
.responsive_square {
|
||||
transform: translate(0.95rem, -1rem);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import type { Meta, StoryObj } from "@storybook/react";
|
||||
import { userEvent, within } from "@storybook/test";
|
||||
import { AkselTheme } from "@/sb-util";
|
||||
import { Feedback, FeedbackForm } from "./Feedback";
|
||||
|
||||
const meta = {
|
||||
title: "Layout/god-praksis/Feedback",
|
||||
component: Feedback,
|
||||
tags: ["autodocs"],
|
||||
decorators: [AkselTheme],
|
||||
} satisfies Meta<typeof Feedback>;
|
||||
|
||||
export default meta;
|
||||
type Story = StoryObj<typeof meta>;
|
||||
|
||||
export const WithOutName: Story = {
|
||||
args: { userState: { signedIn: false, user: null } },
|
||||
};
|
||||
|
||||
export const WithName: Story = {
|
||||
args: {
|
||||
userState: {
|
||||
signedIn: true,
|
||||
user: {
|
||||
email: "email",
|
||||
name: "name",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const InteractionStates = {
|
||||
render: () => {
|
||||
return <FeedbackForm user={{ email: "email", name: "name" }} />;
|
||||
},
|
||||
play: async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
|
||||
const input = canvas.getByLabelText("Innspill");
|
||||
|
||||
await userEvent.click(input);
|
||||
await userEvent.type(input, "e".repeat(500) + "!");
|
||||
|
||||
const submit = canvas.getByText("Send inn");
|
||||
await userEvent.click(submit);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
|
||||
await userEvent.click(input);
|
||||
await userEvent.keyboard("{backspace}");
|
||||
await userEvent.click(submit);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,262 @@
|
||||
import React, { useState } from "react";
|
||||
import { InboxDownIcon, PersonIcon } from "@navikt/aksel-icons";
|
||||
import {
|
||||
Alert,
|
||||
BodyLong,
|
||||
BodyShort,
|
||||
Box,
|
||||
Button,
|
||||
HGrid,
|
||||
HStack,
|
||||
Heading,
|
||||
Link,
|
||||
Textarea,
|
||||
VStack,
|
||||
} from "@navikt/ds-react";
|
||||
import { AuthUser, UserStateT } from "@/auth/auth.types";
|
||||
import { useAuth } from "@/auth/useAuth";
|
||||
import { useSanityData } from "@/hooks/useSanityData";
|
||||
import { AmplitudeEvents, amplitude } from "@/logging";
|
||||
import { SlackFeedbackResponse } from "@/slack";
|
||||
import styles from "./Feedback.module.css";
|
||||
|
||||
type States = "feedbackSent" | "loggedIn" | "error" | "submittingForm";
|
||||
|
||||
export const FeedbackForm = ({ user }: { user: AuthUser }) => {
|
||||
const [state, setState] = useState<States>("loggedIn");
|
||||
const [APIError, setAPIError] = useState<null | string>(null);
|
||||
|
||||
const sanityDocumentId = useSanityData()?.id;
|
||||
const { logout } = useAuth();
|
||||
const [formError, setFormError] = useState<string | null>(null);
|
||||
|
||||
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
setState("loggedIn");
|
||||
|
||||
const formData = new FormData(event.currentTarget);
|
||||
const feedback = (formData.get("feedback") as string) || "";
|
||||
|
||||
if (!feedback) {
|
||||
setFormError("Feltet kan ikke være tomt.");
|
||||
return;
|
||||
}
|
||||
if (feedback.length > 500) {
|
||||
setFormError("Tilbakemeldingen må være under 500 tegn.");
|
||||
return;
|
||||
}
|
||||
|
||||
const body = JSON.stringify({
|
||||
feedback: feedback.slice(0, 500) || "",
|
||||
document_id: sanityDocumentId,
|
||||
});
|
||||
|
||||
setState("submittingForm");
|
||||
fetch("/api/slack/feedback/v1", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body,
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res: SlackFeedbackResponse) => {
|
||||
const feedbackMetadata = {
|
||||
side: window.location.pathname,
|
||||
length: feedback.length,
|
||||
};
|
||||
if (!res.ok) {
|
||||
setAPIError(res.error);
|
||||
setState("error");
|
||||
amplitude.track(AmplitudeEvents.slackfeedback, {
|
||||
result: "error",
|
||||
...feedbackMetadata,
|
||||
});
|
||||
} else {
|
||||
setFormError(null);
|
||||
setState("feedbackSent");
|
||||
amplitude.track(AmplitudeEvents.slackfeedback, {
|
||||
result: "success",
|
||||
...feedbackMetadata,
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
setAPIError("unknownError");
|
||||
setState("error");
|
||||
amplitude.track(AmplitudeEvents.slackfeedback, {
|
||||
result: "error",
|
||||
side: window.location.pathname,
|
||||
length: feedback.length,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
if (state === "feedbackSent") {
|
||||
return (
|
||||
<div>
|
||||
<IntroSection
|
||||
heading="Innspill sendt"
|
||||
description="Ditt innspill er viktig for å holde kvaliteten oppe og innholdet
|
||||
relevant. Takk skal du ha!"
|
||||
/>
|
||||
|
||||
<Button
|
||||
onClick={() => setState("loggedIn")}
|
||||
className="bg-deepblue-600 hover:bg-deepblue-700 active:bg-deepblue-700"
|
||||
>
|
||||
Nytt innspill
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit}>
|
||||
<IntroSection
|
||||
heading="Innspill til artikkelen"
|
||||
description="Har du innspill til artikkelen? Meldingen blir sendt med Slack til team Aksel og folka som har lagd artikkelen 🙌"
|
||||
/>
|
||||
<VStack gap="4">
|
||||
<HStack gap="2">
|
||||
<PersonIcon aria-hidden fontSize="1.5rem" />
|
||||
<BodyShort>{user.name}</BodyShort>
|
||||
<BodyShort>
|
||||
(
|
||||
<Link
|
||||
onClick={() => {
|
||||
logout();
|
||||
}}
|
||||
href="#"
|
||||
>
|
||||
logg ut
|
||||
</Link>
|
||||
)
|
||||
</BodyShort>
|
||||
</HStack>
|
||||
<Textarea
|
||||
name="feedback"
|
||||
label="Innspill"
|
||||
minRows={4}
|
||||
maxLength={500}
|
||||
error={formError}
|
||||
onInput={(element) => {
|
||||
if (element.currentTarget.value.length > 500) {
|
||||
return;
|
||||
}
|
||||
setFormError(null);
|
||||
}}
|
||||
/>
|
||||
</VStack>
|
||||
<Button
|
||||
type="submit"
|
||||
loading={state === "submittingForm"}
|
||||
className="mt-4 bg-deepblue-600 hover:bg-deepblue-700 active:bg-deepblue-700"
|
||||
>
|
||||
Send inn
|
||||
</Button>
|
||||
<>
|
||||
{state === "error" && (
|
||||
<Alert variant="error" className="mt-4" role="alert">
|
||||
Noe gikk galt. Hvis feilen oppstår flere ganger eller du har lyst
|
||||
til å sende tilbakemeldingen direkte finner du oss under{" "}
|
||||
<Link inlineText href="https://nav-it.slack.com/archives/C7NE7A8UF">
|
||||
#aksel-designsystemet
|
||||
</Link>{" "}
|
||||
på slack.
|
||||
<BodyShort
|
||||
textColor="subtle"
|
||||
size="small"
|
||||
className="mt-3"
|
||||
>{`Feil-id: ${APIError}`}</BodyShort>
|
||||
</Alert>
|
||||
)}
|
||||
</>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
|
||||
function IntroSection({
|
||||
heading,
|
||||
description,
|
||||
}: {
|
||||
heading: string;
|
||||
description: string;
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
<Heading
|
||||
level="2"
|
||||
tabIndex={-1}
|
||||
id="scrollToFeedback"
|
||||
size="small"
|
||||
className="mb-1 focus:outline-none"
|
||||
>
|
||||
{heading}
|
||||
</Heading>
|
||||
<BodyLong className="mb-4">{description}</BodyLong>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
type Props = {
|
||||
userState: UserStateT;
|
||||
};
|
||||
|
||||
export const Feedback = ({ userState }: Props) => {
|
||||
const { login } = useAuth(true);
|
||||
|
||||
return (
|
||||
<Box
|
||||
borderRadius="large"
|
||||
background="surface-neutral-subtle"
|
||||
className="mt-20"
|
||||
padding="6"
|
||||
>
|
||||
<HGrid columns={{ xs: "1fr 3.5rem", md: "1fr 4.5rem" }} gap="2">
|
||||
{userState.signedIn ? (
|
||||
<FeedbackForm user={userState.user} />
|
||||
) : (
|
||||
<div>
|
||||
<IntroSection
|
||||
heading="Innspill til artikkelen"
|
||||
description="Logg inn med NAV SSO for å gi innspill til artikkelen"
|
||||
/>
|
||||
<Button
|
||||
onClick={() => login()}
|
||||
className="bg-deepblue-600 hover:bg-deepblue-700 active:bg-deepblue-700"
|
||||
>
|
||||
Logg inn med NAV SSO
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
<div className="responsive-svg relative translate-x-[-0.2rem] translate-y-[0.7rem]">
|
||||
<svg
|
||||
aria-hidden
|
||||
width="1em"
|
||||
height="1em"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className={`${styles.responsive} ${styles.responsive_square}`}
|
||||
>
|
||||
<rect
|
||||
x="0"
|
||||
y="0"
|
||||
width="14"
|
||||
height="14"
|
||||
rx="0.75"
|
||||
transform="translate(12.2 2.5) rotate(45 0 0)"
|
||||
fill="#D6C3EE"
|
||||
/>
|
||||
</svg>
|
||||
<InboxDownIcon
|
||||
className={`${styles.responsive} ${styles.responsive_inbox} absolute`}
|
||||
aria-hidden
|
||||
fontSize="4rem"
|
||||
/>
|
||||
</div>
|
||||
</HGrid>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
import pino from "pino";
|
||||
import { logger as sharedPinoConfig } from "./next-logger.config";
|
||||
|
||||
/**
|
||||
* This logger is not isomorphic, and should only be used on the server
|
||||
*/
|
||||
export const logger: pino.Logger = sharedPinoConfig();
|
||||
@@ -1,31 +0,0 @@
|
||||
const pino = require("pino");
|
||||
|
||||
const logger = (defaultConfig = {}) =>
|
||||
pino({
|
||||
...defaultConfig,
|
||||
timestamp: false,
|
||||
formatters: {
|
||||
level: (label) => {
|
||||
return { level: label };
|
||||
},
|
||||
log: (object) => {
|
||||
if (object.err) {
|
||||
// massage the error object so logs.adeo.no shows stack traces
|
||||
const err =
|
||||
object.err instanceof Error
|
||||
? pino.stdSerializers.err(object.err)
|
||||
: object.err;
|
||||
object.stack_trace = err.stack;
|
||||
object.type = err.type;
|
||||
object.message = err.message;
|
||||
delete object.err;
|
||||
}
|
||||
|
||||
return object;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
logger,
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
const { backendLogger } = require("@navikt/next-logger");
|
||||
|
||||
module.exports = {
|
||||
logger: backendLogger,
|
||||
};
|
||||
@@ -32,6 +32,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@amplitude/analytics-browser": "^2.2.3",
|
||||
"@navikt/next-logger": "1.23.0",
|
||||
"@navikt/oasis": "3.2.1",
|
||||
"@portabletext/react": "^3.0.11",
|
||||
"@sanity/client": "^6.13.3",
|
||||
@@ -41,6 +42,7 @@
|
||||
"@sanity/locale-nb-no": "^1.1.0",
|
||||
"@sanity/table": "1.1.2",
|
||||
"@sanity/vision": "3.34.0",
|
||||
"@slack/web-api": "^7.0.2",
|
||||
"boring-avatars": "1.10.1",
|
||||
"clsx": "^2.1.0",
|
||||
"codesandbox": "^2.2.3",
|
||||
@@ -50,8 +52,9 @@
|
||||
"lodash": "^4.17.21",
|
||||
"lz-string": "^1.5.0",
|
||||
"next": "14.1.1-canary.57",
|
||||
"next-logger": "3.0.2",
|
||||
"next-logger": "^3.0.2",
|
||||
"next-sanity": "5.5.8",
|
||||
"node-cache": "^5.1.2",
|
||||
"pino": "^8.14.1",
|
||||
"prism-react-renderer": "^2.0.0",
|
||||
"react": "^18.0.0",
|
||||
@@ -67,7 +70,8 @@
|
||||
"styled-components": "^6.0.0",
|
||||
"swr": "^1.1.2",
|
||||
"tailwindcss": "^3.3.3",
|
||||
"tinycolor2": "^1.6.0"
|
||||
"tinycolor2": "^1.6.0",
|
||||
"zod": "^3.22.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@axe-core/playwright": "^4.5.2",
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export { pinoLoggingRoute as default } from "@navikt/next-logger";
|
||||
@@ -0,0 +1,326 @@
|
||||
import { SectionBlock, UsersListResponse, WebClient } from "@slack/web-api";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { z } from "zod";
|
||||
import { createChildLogger } from "@navikt/next-logger";
|
||||
import { authProtectedApi } from "@/auth/authProtectedApi";
|
||||
import { getAuthUser } from "@/auth/getAuthUser";
|
||||
import { getClient } from "@/sanity/client.server";
|
||||
import {
|
||||
SlackFeedbackError,
|
||||
SlackFeedbackErrorT,
|
||||
SlackFeedbackResponse,
|
||||
fetchSlackMembers,
|
||||
findUserByEmail,
|
||||
} from "@/slack";
|
||||
|
||||
const maxFeedbackLength = 500;
|
||||
|
||||
const requestBodySchema = z.object({
|
||||
body: z.object({
|
||||
feedback: z
|
||||
.string({
|
||||
required_error: "Message-string is required",
|
||||
})
|
||||
.min(1, "Message-string cannot be empty")
|
||||
.max(
|
||||
maxFeedbackLength,
|
||||
`Message-string cannot be longer than ${maxFeedbackLength} characters`,
|
||||
),
|
||||
document_id: z.string({
|
||||
required_error: "Document-id is required",
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
const client = new WebClient(process.env.SLACK_BOT_TOKEN);
|
||||
|
||||
export default authProtectedApi(sendSlackbotFeedback);
|
||||
|
||||
async function sendSlackbotFeedback(
|
||||
request: NextApiRequest,
|
||||
response: NextApiResponse,
|
||||
) {
|
||||
const logger = createChildLogger("slackbot-feedback");
|
||||
logger.info("Received slackbot feedback request");
|
||||
const user = getAuthUser(request.headers);
|
||||
|
||||
/**
|
||||
* If authenticated user is not found, we return 400.
|
||||
* This should in theory no be possible since api is behind `authProtectedApi`
|
||||
*/
|
||||
if (!user) {
|
||||
return errorResponse(response, SlackFeedbackError.InvalidUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the request with zod before we continue flow
|
||||
*/
|
||||
const validation = requestBodySchema.safeParse({
|
||||
body: request.body,
|
||||
});
|
||||
if (validation.success === false) {
|
||||
return errorResponse(response, SlackFeedbackError.InvalidBody);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanity caches requests with cdn, so no need to cache locally
|
||||
*/
|
||||
const document = await getClient().fetch(
|
||||
`*[_id == $id][0]{
|
||||
"id": _id,
|
||||
"title": heading,
|
||||
"editors": contributors[]->email,
|
||||
"slug": slug.current
|
||||
}`,
|
||||
{
|
||||
id: validation.data.body.document_id,
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* If no document is found, sanity will return `null`
|
||||
*/
|
||||
if (!document) {
|
||||
return errorResponse(response, SlackFeedbackError.InvalidId);
|
||||
}
|
||||
|
||||
const slackMembers = await fetchSlackMembers();
|
||||
if (slackMembers.ok === false) {
|
||||
return errorResponse(response, SlackFeedbackError.NoSlackUsers);
|
||||
}
|
||||
|
||||
/**
|
||||
* We find the sender in list of slack members
|
||||
* Since everyone in NAV has access to login,
|
||||
* but might not use slack we can have some cases where no user is found
|
||||
*/
|
||||
const senderSlackUser = findUserByEmail(user.email, slackMembers.members);
|
||||
|
||||
/**
|
||||
* We use contributors found on article and find their matching slack profiles
|
||||
*/
|
||||
const slackProfileForEditors = document.editors
|
||||
.filter(Boolean)
|
||||
.map((email: string) => findUserByEmail(email, slackMembers.members))
|
||||
.filter(Boolean) as Exclude<UsersListResponse["members"], undefined>;
|
||||
|
||||
let postMessageError = false;
|
||||
|
||||
await client.chat
|
||||
.postMessage({
|
||||
/* ChannelId for #aksel-feedback-bot */
|
||||
channel: "C06PY34NNJH",
|
||||
text: `Tilbakemelding: ${validation.data.body.feedback}`,
|
||||
blocks: [
|
||||
...slackBlock({
|
||||
article: {
|
||||
id: document.id,
|
||||
slug: document.slug,
|
||||
title: document.title,
|
||||
},
|
||||
feedback: validation.data.body.feedback,
|
||||
recievers: slackProfileForEditors
|
||||
.map((x) => x.id)
|
||||
.filter(Boolean) as string[],
|
||||
sender: {
|
||||
email: user.email,
|
||||
slackId: senderSlackUser?.id,
|
||||
},
|
||||
}),
|
||||
...(slackProfileForEditors.length === 0
|
||||
? [
|
||||
{
|
||||
type: "section",
|
||||
text: {
|
||||
type: "mrkdwn",
|
||||
text: ":exclamation: Denne artikkelen har ingen redaktører. @here",
|
||||
},
|
||||
} satisfies SectionBlock,
|
||||
]
|
||||
: []),
|
||||
],
|
||||
})
|
||||
.catch((e) => {
|
||||
postMessageError = true;
|
||||
logger.error(
|
||||
`Error when sending slackbot feedback to private channel: ${e}`,
|
||||
);
|
||||
});
|
||||
|
||||
for (const editor of slackProfileForEditors) {
|
||||
if (!editor.id) {
|
||||
continue;
|
||||
}
|
||||
await client.chat
|
||||
.postMessage({
|
||||
channel: editor.id,
|
||||
text: `Tilbakemelding: ${validation.data.body.feedback}`,
|
||||
blocks: slackBlock({
|
||||
article: {
|
||||
id: document.id,
|
||||
slug: document.slug,
|
||||
title: document.title,
|
||||
},
|
||||
feedback: validation.data.body.feedback,
|
||||
recievers: slackProfileForEditors
|
||||
.map((x) => x.id)
|
||||
.filter(Boolean) as string[],
|
||||
sender: {
|
||||
email: user.email,
|
||||
slackId: senderSlackUser?.id,
|
||||
},
|
||||
}),
|
||||
})
|
||||
.catch((e) => {
|
||||
postMessageError = true;
|
||||
logger.error(`Error when sending slackbot feedback: ${e}`);
|
||||
});
|
||||
}
|
||||
|
||||
if (postMessageError) {
|
||||
return errorResponse(response, SlackFeedbackError.PostMessageError);
|
||||
}
|
||||
|
||||
response.status(200).json(responseJson(true));
|
||||
return;
|
||||
}
|
||||
|
||||
const ErrorMap = {
|
||||
[SlackFeedbackError.InvalidUser]: `Error with getAuthUser in slackbot feedback. This should not happend since we are using authProtectedApi`,
|
||||
[SlackFeedbackError.InvalidBody]: `Error with validation of body in slackbot feedback`,
|
||||
[SlackFeedbackError.InvalidId]: `Error when fetching sanity document for slackbot feedback`,
|
||||
[SlackFeedbackError.NoSlackUsers]: `Error extracting members from slack in slackbot feedback`,
|
||||
[SlackFeedbackError.PostMessageError]: `Error when sending slackbot feedback to private channel or user in slackbot feedback`,
|
||||
};
|
||||
|
||||
function errorResponse(
|
||||
response: NextApiResponse,
|
||||
error: keyof typeof ErrorMap,
|
||||
) {
|
||||
const logger = createChildLogger("slackbot-feedback");
|
||||
logger.error(ErrorMap[error] ?? "unknown error");
|
||||
|
||||
response.status(400).json(responseJson(false, error));
|
||||
}
|
||||
|
||||
function responseJson(
|
||||
valid: boolean,
|
||||
message?: SlackFeedbackErrorT,
|
||||
): SlackFeedbackResponse {
|
||||
if (!valid && message) {
|
||||
return { ok: false, error: message };
|
||||
}
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
type SlackBlockT = {
|
||||
feedback: string;
|
||||
article: { slug: string; title: string; id: string };
|
||||
recievers: string[];
|
||||
sender: { email: string; slackId?: string };
|
||||
};
|
||||
|
||||
function slackBlock({ feedback, article, recievers, sender }: SlackBlockT) {
|
||||
return [
|
||||
{
|
||||
type: "header",
|
||||
text: {
|
||||
type: "plain_text",
|
||||
/* TODO: Endre melding basert på om du er editor eller temakontakt */
|
||||
text: "Innspill til Aksel-artikkel du har medvirket til",
|
||||
emoji: true,
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
type: "rich_text",
|
||||
elements: [
|
||||
{
|
||||
type: "rich_text_quote",
|
||||
elements: [
|
||||
{
|
||||
type: "text",
|
||||
text: `\n${feedback}\n\n`,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: "divider",
|
||||
},
|
||||
{
|
||||
type: "rich_text",
|
||||
elements: [
|
||||
{
|
||||
type: "rich_text_section",
|
||||
elements: [
|
||||
{
|
||||
type: "text",
|
||||
text: `Avsender:\n`,
|
||||
style: {
|
||||
bold: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
...(sender.slackId
|
||||
? { type: "user", user_id: sender.slackId }
|
||||
: { type: "text", text: sender.email }),
|
||||
},
|
||||
{
|
||||
type: "text",
|
||||
text: "\n\nArtikkel:\n",
|
||||
style: {
|
||||
bold: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "link",
|
||||
url: `https://aksel.nav.no/${article.slug}`,
|
||||
text: `${article.title}\n\n`,
|
||||
},
|
||||
{
|
||||
type: "text",
|
||||
text: "\n\nMedvirkende (disse fikk tilbakemeldingen):\n",
|
||||
style: {
|
||||
bold: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: "rich_text_list",
|
||||
style: "bullet",
|
||||
indent: 0,
|
||||
border: 0,
|
||||
elements: recievers.map((reciever) => ({
|
||||
type: "rich_text_section",
|
||||
elements: [{ type: "user", user_id: reciever }],
|
||||
})),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: "divider",
|
||||
},
|
||||
{
|
||||
type: "section",
|
||||
text: {
|
||||
type: "mrkdwn",
|
||||
text: "Rediger artikkel ",
|
||||
},
|
||||
accessory: {
|
||||
type: "button",
|
||||
text: {
|
||||
type: "plain_text",
|
||||
text: ":pencil2: Rediger",
|
||||
emoji: true,
|
||||
},
|
||||
url: `https://aksel.nav.no/admin/prod/intent/edit/id=${article.id}`,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "divider",
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -1,14 +1,21 @@
|
||||
import { useState } from "react";
|
||||
import { Radio, RadioGroup } from "@navikt/ds-react";
|
||||
import { withDsExample } from "@/web/examples/withDsExample";
|
||||
|
||||
const Example = () => {
|
||||
const handleChange = (val: any) => console.log(val);
|
||||
const [error, setError] = useState(
|
||||
"Du må velge en aldersgruppe før du kan gå videre.",
|
||||
);
|
||||
const handleChange = (val: string) => {
|
||||
console.log(val);
|
||||
setError("");
|
||||
};
|
||||
|
||||
return (
|
||||
<RadioGroup
|
||||
legend="Velg din aldersgruppe."
|
||||
onChange={(val: any) => handleChange(val)}
|
||||
error="Vi fant ingen resultater på din aldersgruppe."
|
||||
onChange={handleChange}
|
||||
error={error}
|
||||
>
|
||||
<Radio value="10">10-20 år</Radio>
|
||||
<Radio value="20">21-45 år</Radio>
|
||||
|
||||
@@ -3,7 +3,8 @@ import { GetServerSideProps } from "next/types";
|
||||
import { Suspense, lazy } from "react";
|
||||
import { ChevronRightIcon } from "@navikt/aksel-icons";
|
||||
import { BodyLong, BodyShort, Detail, Heading, Label } from "@navikt/ds-react";
|
||||
import { validateWonderwallToken } from "@/auth/validateWonderwall";
|
||||
import { UserStateT } from "@/auth/auth.types";
|
||||
import { getAuthUserState } from "@/auth/getUserState";
|
||||
import ArtikkelCard from "@/cms/cards/ArtikkelCard";
|
||||
import Footer from "@/layout/footer/Footer";
|
||||
import Header from "@/layout/header/Header";
|
||||
@@ -25,6 +26,7 @@ import {
|
||||
} from "@/types";
|
||||
import { abbrName, dateStr, generateTableOfContents } from "@/utils";
|
||||
import { BreadCrumbs } from "@/web/BreadCrumbs";
|
||||
import { Feedback } from "@/web/Feedback/Feedback";
|
||||
import { SEO } from "@/web/seo/SEO";
|
||||
import TableOfContents from "@/web/toc/TableOfContents";
|
||||
import NotFotfund from "../../404";
|
||||
@@ -36,7 +38,7 @@ type PageProps = NextPageT<{
|
||||
publishDate: string;
|
||||
verifiedDate: string;
|
||||
toc: TableOfContentsT;
|
||||
signedIn: boolean;
|
||||
userState: UserStateT;
|
||||
}>;
|
||||
|
||||
export const query = `{
|
||||
@@ -68,7 +70,7 @@ export const query = `{
|
||||
export const getServerSideProps: GetServerSideProps = async (
|
||||
context,
|
||||
): Promise<PageProps> => {
|
||||
const signedIn = await validateWonderwallToken(context.req.headers);
|
||||
const userState = await getAuthUserState(context.req.headers);
|
||||
|
||||
const isPreview = context.preview ?? false;
|
||||
|
||||
@@ -93,7 +95,7 @@ export const getServerSideProps: GetServerSideProps = async (
|
||||
content: page?.content,
|
||||
type: "aksel_artikkel",
|
||||
}),
|
||||
signedIn,
|
||||
userState,
|
||||
},
|
||||
notFound: !page && !isPreview,
|
||||
};
|
||||
@@ -104,6 +106,7 @@ const Page = ({
|
||||
publishDate,
|
||||
verifiedDate,
|
||||
toc,
|
||||
userState,
|
||||
}: PageProps["props"]) => {
|
||||
if (!data) {
|
||||
return <NotFotfund />;
|
||||
@@ -253,6 +256,7 @@ const Page = ({
|
||||
<BodyShort as="span" className="text-text-subtle">
|
||||
Publisert: {publishDate}
|
||||
</BodyShort>
|
||||
<Feedback userState={userState} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
"@/preview": ["./components/website-modules/preview/WithPreview.tsx"],
|
||||
"@/logging": ["./components/logging/index.ts"],
|
||||
"@/utils": ["./components/utils/index.ts"],
|
||||
"@/slack": ["./components/utils/slack/index.ts"],
|
||||
"@/layout/*": ["./components/layout/*"],
|
||||
"@/assets/*": ["./components/assets/*"],
|
||||
"@/web/*": ["./components/website-modules/*"],
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"@/preview": ["./components/website-modules/preview/WithPreview.tsx"],
|
||||
"@/logging": ["./components/logging/index.ts"],
|
||||
"@/utils": ["./components/utils/index.ts"],
|
||||
"@/slack": ["./components/utils/slack/index.ts"],
|
||||
"@/layout/*": ["./components/layout/*"],
|
||||
"@/assets/*": ["./components/assets/*"],
|
||||
"@/web/*": ["./components/website-modules/*"],
|
||||
|
||||
Reference in new issue
Block a user