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

Use WizardNavigationButtons everywhere #832

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
26 changes: 8 additions & 18 deletions src/components/configuration/partials/wizard/ThemeDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import cn from "classnames";
import { Formik } from "formik";
import GeneralPage from "./GeneralPage";
import BumperPage from "./BumperPage";
Expand All @@ -16,6 +14,7 @@ import { NewThemeSchema } from "../../../../utils/validate";
import { useAppDispatch, useAppSelector } from "../../../../store";
import { updateThemeDetails } from "../../../../slices/themeDetailsSlice";
import { Details } from "../../../../slices/themeSlice";
import WizardNavigationButtons from "../../../shared/wizard/WizardNavigationButtons";

/**
* This component manages the pages of the theme details
Expand All @@ -25,7 +24,6 @@ const ThemeDetails : React.FC<{
}> = ({
close,
}) => {
const { t } = useTranslation();
const dispatch = useAppDispatch();

const [page, setPage] = useState(0);
Expand Down Expand Up @@ -116,21 +114,13 @@ const ThemeDetails : React.FC<{
{page === 4 && <WatermarkPage formik={formik} isEdit />}
{page === 5 && <UsagePage themeUsage={themeUsage} />}
{/* submit and cancel button */}
<footer>
<button
className={cn("submit", {
active: formik.dirty && formik.isValid,
inactive: !(formik.dirty && formik.isValid),
})}
disabled={!(formik.dirty && formik.isValid)}
onClick={() => formik.handleSubmit()}
>
{t("SUBMIT")}
</button>
<button className="cancel" onClick={() => close()}>
{t("CANCEL")}
</button>
</footer>
<WizardNavigationButtons
isLast
formik={formik}
previousPage={() => close()}
createTranslationString={"SUBMIT"}
cancelTranslationString={"CANCEL"}
/>

<div className="btm-spacer" />
</div>
Expand Down
36 changes: 10 additions & 26 deletions src/components/events/partials/ModalTabsAndPages/NewAccessPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import cn from "classnames";
import Notifications from "../../../shared/Notifications";
import {
Role,
Expand All @@ -19,6 +18,7 @@ import { filterRoles, getAclTemplateText } from "../../../../utils/aclUtils";
import { useAppDispatch, useAppSelector } from "../../../../store";
import { fetchSeriesDetailsAcls } from "../../../../slices/seriesDetailsSlice";
import { getSeriesDetailsAcl } from "../../../../selectors/seriesDetailsSelectors";
import WizardNavigationButtons from "../../../shared/wizard/WizardNavigationButtons";

/**
* This component renders the access page for new events and series in the wizards.
Expand Down Expand Up @@ -344,31 +344,15 @@ const NewAccessPage = ({
</div>
</div>
{/* Button for navigation to next page and previous page */}
<footer>
<button
type="submit"
className={cn("submit", {
active: formik.dirty && formik.isValid,
inactive: !(formik.dirty && formik.isValid),
})}
disabled={!(formik.dirty && formik.isValid)}
onClick={async () => {
if (await dispatch(checkAcls(formik.values.acls))) {
nextPage(formik.values);
}
}}
tabIndex={100}
>
{t("WIZARD.NEXT_STEP")}
</button>
<button
className="cancel"
onClick={() => previousPage(formik.values, false)}
tabIndex={101}
>
{t("WIZARD.BACK")}
</button>
</footer>
<WizardNavigationButtons
formik={formik}
nextPage={async () => {
if (await dispatch(checkAcls(formik.values.acls))) {
nextPage(formik.values);
}
}}
previousPage={previousPage}
/>

<div className="btm-spacer" />
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { useEffect } from "react";
import { useTranslation } from "react-i18next";
import cn from "classnames";
import { getWorkflowDef } from "../../../../selectors/workflowSelectors";
import RenderWorkflowConfig from "../wizards/RenderWorkflowConfig";
import { setDefaultConfig } from "../../../../utils/workflowPanelUtils";
import DropDown from "../../../shared/DropDown";
import { useAppDispatch, useAppSelector } from "../../../../store";
import { fetchWorkflowDef } from "../../../../slices/workflowSlice";
import { FormikProps } from "formik";
import WizardNavigationButtons from "../../../shared/wizard/WizardNavigationButtons";

/**
* This component renders the processing page for new events in the new event wizard.
Expand Down Expand Up @@ -120,25 +120,11 @@ const NewProcessingPage = <T extends RequiredFormProps>({
</div>

{/* Button for navigation to next page and previous page */}
<footer>
<button
type="submit"
className={cn("submit", {
active: formik.values.processingWorkflow && formik.isValid,
inactive: !(formik.values.processingWorkflow && formik.isValid),
})}
disabled={!(formik.values.processingWorkflow && formik.isValid)}
onClick={() => {
nextPage(formik.values);
}}
tabIndex={100}
>
{t("WIZARD.NEXT_STEP")}
</button>
<button className="cancel" onClick={() => previous()} tabIndex={101}>
{t("WIZARD.BACK")}
</button>
</footer>
<WizardNavigationButtons
formik={formik}
nextPage={nextPage}
previousPage={() => previous()}
/>

<div className="btm-spacer" />
</>
Expand Down
48 changes: 16 additions & 32 deletions src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import cn from "classnames";
import Notifications from "../../../shared/Notifications";
import { DatePicker } from "@mui/x-date-pickers/DatePicker";
import {
Expand Down Expand Up @@ -42,6 +41,7 @@ import { Recording, fetchRecordings } from "../../../../slices/recordingSlice";
import { removeNotificationWizardForm } from "../../../../slices/notificationSlice";
import { parseISO } from "date-fns";
import { checkConflicts } from "../../../../slices/eventSlice";
import WizardNavigationButtons from "../../../shared/wizard/WizardNavigationButtons";

/**
* This component renders the source page for new events in the new event wizard.
Expand Down Expand Up @@ -223,37 +223,21 @@ const NewSourcePage = <T extends RequiredFormProps>({
</div>

{/* Button for navigation to next page and previous page */}
<footer>
<button
type="submit"
className={cn("submit", {
active: formik.dirty && formik.isValid,
inactive: !(formik.dirty && formik.isValid),
})}
disabled={!(formik.dirty && formik.isValid)}
onClick={async () => {
removeOldNotifications();
const noConflicts = await dispatch(checkConflicts(formik.values));
if (Array.isArray(noConflicts)) {
setConflicts(noConflicts);
}
if ((typeof noConflicts == "boolean" && noConflicts)
|| (Array.isArray(noConflicts) && noConflicts.length === 0)) {
nextPage(formik.values);
}
}}
tabIndex={100}
>
{t("WIZARD.NEXT_STEP")}
</button>
<button
className="cancel"
onClick={() => previousPage(formik.values, false)}
tabIndex={101}
>
{t("WIZARD.BACK")}
</button>
</footer>
<WizardNavigationButtons
formik={formik}
nextPage={async () => {
removeOldNotifications();
const noConflicts = await dispatch(checkConflicts(formik.values));
if (Array.isArray(noConflicts)) {
setConflicts(noConflicts);
}
if ((typeof noConflicts == "boolean" && noConflicts)
|| (Array.isArray(noConflicts) && noConflicts.length === 0)) {
nextPage(formik.values);
}
}}
previousPage={previousPage}
/>

<div className="btm-spacer" />
</>
Expand Down
2 changes: 1 addition & 1 deletion src/components/events/partials/wizards/NewEventWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const NewEventWizard: React.FC<{
}
};

const previousPage = (values: typeof initialValues, twoPagesBack?: boolean) => {
const previousPage = (values: typeof initialValues, twoPagesBack: boolean = false) => {
setSnapshot(values);
// if previous page is hidden or not always shown, than go back two pages
if (steps[page - 1].hidden || twoPagesBack) {
Expand Down
8 changes: 6 additions & 2 deletions src/components/shared/wizard/WizardNavigationButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ const WizardNavigationButtons = <T,>({
formik,
nextPage,
previousPage,
createTranslationString,
cancelTranslationString,
}: {
isFirst?: boolean,
isLast?: boolean,
noValidation?: boolean,
formik: FormikProps<T>,
nextPage?: (values: T) => void,
previousPage?: (values: T) => void,
createTranslationString?: string,
cancelTranslationString?: string,
}) => {
const { t } = useTranslation();

Expand All @@ -42,7 +46,7 @@ const WizardNavigationButtons = <T,>({
}}
tabIndex={100}
>
{t("WIZARD.CREATE")}
{createTranslationString ? t(createTranslationString) : t("WIZARD.CREATE")}
</button>
) : (
<button
Expand All @@ -65,7 +69,7 @@ const WizardNavigationButtons = <T,>({
}}
tabIndex={101}
>
{t("WIZARD.BACK")}
{cancelTranslationString ? t(cancelTranslationString) : t("WIZARD.BACK")}
</button>
)}
</footer>
Expand Down
23 changes: 8 additions & 15 deletions src/components/users/partials/wizard/NewUserWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { NewUserSchema } from "../../../../utils/validate";
import { NewUser, postNewUser } from "../../../../slices/userSlice";
import { useAppDispatch, useAppSelector } from "../../../../store";
import { Tooltip } from "../../../shared/Tooltip";
import WizardNavigationButtons from "../../../shared/wizard/WizardNavigationButtons";

/**
* This component renders the new user wizard
Expand Down Expand Up @@ -82,21 +83,13 @@ const NewUserWizard = ({
{tab === 1 && <UserRolesTab formik={formik} />}

{/* Navigation buttons and validation */}
<footer>
<button
className={cn("submit", {
active: formik.dirty && formik.isValid,
inactive: !(formik.dirty && formik.isValid),
})}
disabled={!(formik.dirty && formik.isValid)}
onClick={() => formik.handleSubmit()}
>
{t("SUBMIT")}
</button>
<button className="cancel" onClick={() => close()}>
{t("CANCEL")}
</button>
</footer>
<WizardNavigationButtons
isLast
formik={formik}
nextPage={() => formik.handleSubmit()}
previousPage={() => close()}
cancelTranslationString={"CANCEL"}
/>
</>
);
}}
Expand Down
1 change: 1 addition & 0 deletions src/utils/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const NewEventSchema = [
then: () => Yup.string().required("Required"),
}),
}),
Yup.object().shape({}),
Yup.object().shape({
processingWorkflow: Yup.string().required("Required"),
}),
Expand Down
Loading