Skip to content

Commit

Permalink
Add responsibleselector to modal
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarvelle committed Jan 10, 2025
1 parent e078257 commit 2698fa4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/containers/ConceptPage/ConceptForm/ConceptForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,12 @@ const ConceptForm = ({
<ConceptFormFooter
entityStatus={concept?.status}
conceptChanged={!!conceptChanged}
inModal={inModal}
savedToServer={savedToServer}
isNewlyCreated={isNewlyCreated}
showSimpleFooter={!concept?.id}
onClose={onClose}
responsibleId={concept?.responsible?.responsibleId}
responsibleId={concept?.responsible?.responsibleId ?? ndlaId}
/>
</FormWrapper>
);
Expand Down
30 changes: 24 additions & 6 deletions src/containers/ConceptPage/ConceptForm/ConceptFormFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { useFormikContext } from "formik";
import { useCallback, useState } from "react";
import { useTranslation } from "react-i18next";
import { Button } from "@ndla/primitives";

Check failure on line 12 in src/containers/ConceptPage/ConceptForm/ConceptFormFooter.tsx

View workflow job for this annotation

GitHub Actions / Unit tests

'Button' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 12 in src/containers/ConceptPage/ConceptForm/ConceptFormFooter.tsx

View workflow job for this annotation

GitHub Actions / Unit tests

'Button' is defined but never used. Allowed unused vars must match /^_/u
import { styled } from "@ndla/styled-system/jsx";
Expand All @@ -15,6 +16,7 @@ import { FormActionsContainer } from "../../../components/FormikForm";
import SaveButton from "../../../components/SaveButton";
import EditorFooter from "../../../components/SlateEditor/EditorFooter";
import { SAVE_BUTTON_ID } from "../../../constants";
import ResponsibleSelect from "../../../containers/FormikForm/components/ResponsibleSelect";
import { useConceptStateMachine } from "../../../modules/concept/conceptQueries";
import { isFormikFormDirty } from "../../../util/formHelper";
import { AlertDialogWrapper } from "../../FormikForm";
Expand Down Expand Up @@ -44,13 +46,13 @@ const ConceptFormFooter = ({
savedToServer,
isNewlyCreated,
showSimpleFooter,
onClose,
responsibleId,
}: Props) => {
const { t } = useTranslation();
const formikContext = useFormikContext<ConceptFormValues>();
const conceptStateMachine = useConceptStateMachine();
const { values, errors, initialValues, dirty, isSubmitting, submitForm } = formikContext;
const [responsible, setResponsible] = useState<string | undefined>(undefined);
const { values, errors, initialValues, dirty, isSubmitting, submitForm, setFieldValue } = formikContext;
const formIsDirty = isFormikFormDirty({
values,
initialValues,
Expand All @@ -60,15 +62,31 @@ const ConceptFormFooter = ({

const disableSave = Object.keys(errors).length > 0;

const updateResponsible = useCallback(
async (responsible: string | undefined) => {
try {
setResponsible(responsible);
setFieldValue("responsibleId", responsible ? responsible : null);
} catch (error) {
//catchError(error, createMessage);
}
},
[setFieldValue],
);

if (inModal) {
return (
<StyledFormActionsContainer>
<Button variant="secondary" onClick={onClose}>
{t("form.abort")}
</Button>
<ResponsibleSelect
key="concept-modal-responsible-select"
responsible={responsible}
setResponsible={setResponsible}
onSave={updateResponsible}
responsibleId={responsibleId}
/>
<SaveButton
id={SAVE_BUTTON_ID}
type={!inModal ? "submit" : "button"}
type={"button"}
loading={isSubmitting}
formIsDirty={formIsDirty}
showSaved={!!savedToServer && !formIsDirty}
Expand Down

0 comments on commit 2698fa4

Please sign in to comment.