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

chore: Exchange gui actions with AC DialogActions component #1856

Merged
merged 1 commit into from
Feb 28, 2025
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
4 changes: 2 additions & 2 deletions packages/frontend/src/api/useDialogById.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from 'bff-types-generated';
import { AttachmentUrlConsumer } from 'bff-types-generated';
import { t } from 'i18next';
import type { GuiActionButtonProps } from '../components';
import type { DialogActionProps } from '../components/InboxItem/InboxItemDetail.tsx';
import { QUERY_KEYS } from '../constants/queryKeys.ts';
import { type ValueType, getPreferredPropertyByLocale } from '../i18n/property.ts';
import { useOrganizations } from '../pages/Inbox/useOrganizations.ts';
Expand Down Expand Up @@ -64,7 +64,7 @@ export interface DialogByIdDetails {
sender: Participant;
receiver: Participant;
title: string;
guiActions: GuiActionButtonProps[];
guiActions: DialogActionProps[];
additionalInfo: { value: string; mediaType: string } | undefined;
attachments: AttachmentFieldsFragment[];
dialogToken: string;
Expand Down
129 changes: 0 additions & 129 deletions packages/frontend/src/components/InboxItem/GuiActions.tsx

This file was deleted.

69 changes: 66 additions & 3 deletions packages/frontend/src/components/InboxItem/InboxItemDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import {
Article,
type AttachmentLinkProps,
type DialogActionButtonProps,
DialogActions,
DialogAttachments,
DialogBody,
type DialogButtonPriority,
DialogHeader,
} from '@altinn/altinn-components';
import type { ReactElement } from 'react';
import { type ReactElement, useState } from 'react';
import { useTranslation } from 'react-i18next';
import type { DialogActivity, DialogByIdDetails, DialogTransmission } from '../../api/useDialogById.tsx';
import { getPreferredPropertyByLocale } from '../../i18n/property.ts';
Expand All @@ -15,7 +18,6 @@ import { Activity } from '../Activity';
import { AdditionalInfoContent } from '../AdditonalInfoContent';
import { MainContentReference } from '../MainContentReference';
import { Transmission } from '../Transmission';
import { GuiActions } from './GuiActions.tsx';
import styles from './inboxItemDetail.module.css';

interface InboxItemDetailProps {
Expand Down Expand Up @@ -47,6 +49,51 @@ interface InboxItemDetailProps {
* />
*/

export interface DialogActionProps {
id: string;
title: string;
url: string;
httpMethod: string;
prompt?: string;
disabled?: boolean;
priority: string;
}

const handleDialogActionClick = async (
props: DialogActionProps,
dialogToken: string,
responseFinished: () => void,
): Promise<void> => {
const { url, httpMethod, prompt } = props;

if (prompt && !window.confirm(prompt)) {
responseFinished();
return;
}

if (httpMethod === 'GET') {
responseFinished();
window.open(url, '_blank');
} else {
try {
const response = await fetch(url, {
method: httpMethod,
headers: {
Authorization: `Bearer ${dialogToken}`,
},
});

if (!response.ok) {
console.error(`Error: ${response.statusText}`);
}
} catch (error) {
console.error('Error performing action:', error);
} finally {
responseFinished();
}
}
};

export const InboxItemDetail = ({ dialog }: InboxItemDetailProps): ReactElement => {
const { t } = useTranslation();
const format = useFormat();
Expand Down Expand Up @@ -95,6 +142,22 @@ export const InboxItemDetail = ({ dialog }: InboxItemDetailProps): ReactElement
const formatString = clockPrefix ? `do MMMM yyyy '${clockPrefix}' HH.mm` : `do MMMM yyyy HH.mm`;
const dueAtLabel = dueAt ? format(dueAt, formatString) : '';

const [isLoading, setIsLoading] = useState<string>('');

const dialogActions: DialogActionButtonProps[] = guiActions.map((action) => ({
id: action.id,
label: action.title,
disabled: !!isLoading || action.disabled,
priority: action.priority.toLocaleLowerCase() as DialogButtonPriority,
url: action.url,
httpMethod: action.httpMethod,
loading: isLoading === action.id,
onClick: () => {
setIsLoading(action.id);
handleDialogActionClick(action, dialogToken, () => setIsLoading(''));
},
}));

return (
<Article padding={6} spacing={6}>
<DialogHeader dueAt={dueAt} dueAtLabel={dueAtLabel} status={getDialogStatus(status, t)} title={title} />
Expand All @@ -114,7 +177,7 @@ export const InboxItemDetail = ({ dialog }: InboxItemDetailProps): ReactElement
items={attachmentItems}
/>
)}
{guiActions.length > 0 && <GuiActions actions={guiActions} dialogToken={dialogToken} />}
<DialogActions items={dialogActions} />
</DialogBody>
<AdditionalInfoContent mediaType={additionalInfo?.mediaType} value={additionalInfo?.value} />
{activities.length > 0 && (
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion packages/frontend/src/components/InboxItem/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './InboxItems.tsx';
export * from './InboxItemDetail.tsx';
export * from './GuiActions.tsx';