Skip to content

Commit

Permalink
moved buttons into components, registered all components
Browse files Browse the repository at this point in the history
  • Loading branch information
rinrub committed Feb 1, 2024
1 parent 837b3d2 commit dc6d466
Show file tree
Hide file tree
Showing 34 changed files with 3,655 additions and 676 deletions.
25 changes: 21 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.12.0",
"@ungap/structured-clone": "^1.2.0",
"@vitejs/plugin-react": "^4.2.1",
"@wojtekmaj/enzyme-adapter-react-17": "^0.8.0",
"babel-jest": "^27.4.2",
"babel-loader": "^8.2.3",
Expand Down Expand Up @@ -117,25 +118,26 @@
"redux-thunk": "^2.4.2",
"resolve": "^1.22.2",
"rimraf": "^3.0.2",
"sass": "^1.69.0",
"tabbable": "^6.2.0",
"typescript": "^4.8.3",
"vite": "^4.4.5",
"vite-plugin-require": "^1.1.13",
"vite-tsconfig-paths": "^4.2.1",
"whatwg-fetch": "^2.0.4",
"xml2js": "^0.6.2",
"yargs": "^17.7.2",
"@vitejs/plugin-react": "^4.2.1",
"sass": "^1.69.0"
"yargs": "^17.7.2"
},
"dependencies": {
"@hookform/resolvers": "^3.3.4",
"dompurify": "^2.0.8",
"fhirpath": "2.7.3",
"immer": "^9.0.6",
"isomorphic-fetch": "^3.0.0",
"marked": "^3.0.8",
"react-collapse": "^5.1.1",
"uuid": "^9.0.0"
"uuid": "^9.0.0",
"zod": "^3.22.4"
},
"browserslist": [
"> 0.2% in NO",
Expand Down
1 change: 0 additions & 1 deletion src/components/RenderFormItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export const RenderFormItems = ({
item: QuestionnaireItem,
answer: QuestionnaireResponseItemAnswer
): void => {
console.log(newState.refero.form);
if (onChange && newState.refero.form.FormDefinition.Content && newState.refero.form.FormData.Content) {
const actionRequester = new ActionRequester(newState.refero.form.FormDefinition.Content, newState.refero.form.FormData.Content);

Expand Down
92 changes: 0 additions & 92 deletions src/components/formButtons.tsx

This file was deleted.

23 changes: 23 additions & 0 deletions src/components/formButtons/CancelFormButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React, { ReactElement } from 'react';

import { ButtonType } from '../../types/formTypes/formButton';

import Button from '@helsenorge/designsystem-react/components/Button';

import { cancelButtonStyle } from '../../styles/formButtonStyles';

type Props = {
onCancelButtonClicked?: () => void;
cancelButtonText: string;
};

export const CancelFormButton = ({ cancelButtonText, onCancelButtonClicked }: Props): ReactElement => {
return (
<div key={ButtonType.cancelButton} className="cancelButtonStyle">
<style>{cancelButtonStyle}</style>
<Button variant="borderless" onClick={onCancelButtonClicked}>
{cancelButtonText}
</Button>
</div>
);
};
26 changes: 26 additions & 0 deletions src/components/formButtons/PauseFormButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { ReactElement } from 'react';

import { ButtonType } from '../../types/formTypes/formButton';

import Button from '@helsenorge/designsystem-react/components/Button';

import { displayPauseButtonOnSmallScreen, hidePauseButtonOnSmallScreen, pauseButtonStyle } from '../../styles/formButtonStyles';

type Props = {
onPauseButtonClicked?: () => void;
pauseButtonText: string;
isHelsenorgeForm?: boolean;
pauseButtonDisabled?: boolean;
};

export const PauseFormButton = ({ pauseButtonText, onPauseButtonClicked, pauseButtonDisabled, isHelsenorgeForm }: Props): ReactElement => {
return (
<div key={ButtonType.pauseButton} className="pauseButtonStyle">
<style>{pauseButtonStyle}</style>
<style>{isHelsenorgeForm ? hidePauseButtonOnSmallScreen : displayPauseButtonOnSmallScreen}</style>
<Button variant="outline" disabled={pauseButtonDisabled} onClick={onPauseButtonClicked}>
{pauseButtonText}
</Button>
</div>
);
};
23 changes: 23 additions & 0 deletions src/components/formButtons/SubmitFormButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React, { ReactElement } from 'react';

import { ButtonType } from '../../types/formTypes/formButton';

import Button from '@helsenorge/designsystem-react/components/Button';

import { submitButtonStyle } from '../../styles/formButtonStyles';
type Props = {
submitButtonDisabled?: boolean;
onSubmitButtonClicked?: (() => void) | ((e: React.FormEvent) => void);
submitButtonText: string;
};

export const SubmitFormButton = ({ submitButtonText, submitButtonDisabled, onSubmitButtonClicked }: Props): ReactElement => {
return (
<div key={ButtonType.submitButton} className="submitButtonStyle">
<style>{submitButtonStyle}</style>
<Button type="submit" disabled={submitButtonDisabled} onClick={onSubmitButtonClicked}>
{submitButtonText}
</Button>
</div>
);
};
69 changes: 69 additions & 0 deletions src/components/formButtons/formButtons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React, { ReactElement } from 'react';

import { ButtonType, buttonOrderNormalView, buttonOrderStepView } from '../../types/formTypes/formButton';

import { CancelFormButton } from './CancelFormButton';
import { PauseFormButton } from './PauseFormButton';
import { SubmitFormButton } from './SubmitFormButton';
import { formButtonsWrapper } from '../../styles/formButtonStyles';

interface FormButtonsInterface {
submitButtonText: string;
cancelButtonText: string;
pauseButtonText: string;
submitButtonDisabled?: boolean;
pauseButtonDisabled?: boolean;
onSubmitButtonClicked?: (() => void) | ((e: React.FormEvent) => void);
onCancelButtonClicked?: () => void;
onPauseButtonClicked?: () => void;
isHelsenorgeForm?: boolean;
isStepView?: boolean;
}

const FormButtons = ({
isStepView,
submitButtonText,
cancelButtonText,
pauseButtonText,
submitButtonDisabled,
pauseButtonDisabled,
onSubmitButtonClicked,
onCancelButtonClicked,
onPauseButtonClicked,
isHelsenorgeForm,
}: FormButtonsInterface): JSX.Element | null => {
const buttonOrder = isStepView ? buttonOrderStepView : buttonOrderNormalView;

return (
<div className="formButtonsWrapper">
<style>{formButtonsWrapper}</style>
{Object.values(buttonOrder).map((buttonType: ButtonType): ReactElement => {
switch (buttonType) {
case ButtonType.pauseButton:
return (
<PauseFormButton
pauseButtonText={pauseButtonText}
isHelsenorgeForm={isHelsenorgeForm}
onPauseButtonClicked={onPauseButtonClicked}
pauseButtonDisabled={pauseButtonDisabled}
/>
);
case ButtonType.cancelButton:
return <CancelFormButton cancelButtonText={cancelButtonText} onCancelButtonClicked={onCancelButtonClicked} />;
case ButtonType.submitButton:
return (
<SubmitFormButton
onSubmitButtonClicked={onSubmitButtonClicked}
submitButtonDisabled={submitButtonDisabled}
submitButtonText={submitButtonText}
/>
);
default:
return <></>;
}
})}
</div>
);
};

export default FormButtons;
11 changes: 1 addition & 10 deletions src/components/formcomponents/attachment/attachment.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';


import { connect } from 'react-redux';
import { ThunkDispatch } from 'redux-thunk';

Expand Down Expand Up @@ -167,16 +168,6 @@ const AttachmentComponent = ({
return '';
};

// React.useMemo(() => {
// const responseItemHasChanged = responseItem !== responseItem;
// const helpItemHasChanged = isHelpOpen !== isHelpOpen;
// const answerHasChanged = answer !== answer;
// const resourcesHasChanged = JSON.stringify(resources) !== JSON.stringify(resources);
// const repeats = item.repeats ?? false;

// return responseItemHasChanged || helpItemHasChanged || resourcesHasChanged || repeats || answerHasChanged;
// }, [responseItem, isHelpOpen, answer, resources, item]);

const subLabelText = getSublabelText(item, onRenderMarkdown, questionnaire, resources);

if (pdf || isReadOnly(item)) {
Expand Down
Loading

0 comments on commit dc6d466

Please sign in to comment.