Skip to content

Commit

Permalink
frontend: Extending Wizard props and fixing issue with user info not …
Browse files Browse the repository at this point in the history
…breaking (#2960)
  • Loading branch information
jdslaugh committed Mar 25, 2024
1 parent 95d5957 commit 6c719a3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
2 changes: 2 additions & 0 deletions frontend/packages/core/src/AppLayout/user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ const AvatarListItemIcon = styled(ListItemIcon)({
const AvatarListItemText = styled(MuiListItemText)(({ theme }: { theme: Theme }) => ({
paddingLeft: "16px",
margin: "0px",
wordBreak: "break-all",
textWrap: "wrap",
".MuiTypography-root": {
color: alpha(theme.palette.secondary[900], 0.9),
fontSize: "14px",
Expand Down
51 changes: 38 additions & 13 deletions frontend/packages/wizard/src/wizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@ import type { WizardStepProps } from "./step";
interface WizardProps
extends Pick<ContainerProps, "width" | "className">,
Pick<MuiStepperProps, "orientation"> {
children: React.ReactElement<WizardStepProps> | React.ReactElement<WizardStepProps>[];
children:
| React.ReactNode
| React.ReactElement<WizardStepProps>
| React.ReactElement<WizardStepProps>[];
dataLayout: ManagerLayout;
heading?: string;
heading?: string | React.ReactElement;
}

export interface WizardChild {
name: string;
showNPS?: boolean;
confirm?: {
startOver: boolean;
startOverText?: string;
};
}

interface WizardChildren extends JSX.Element {
Expand Down Expand Up @@ -145,10 +153,12 @@ const Wizard = ({
displayWarnings: (warnings: string[]) => {
setGlobalWarnings(warnings);
},
onBack: (params: { toOrigin: boolean }) => {
onBack: ({ toOrigin, keepSearch = false }: { toOrigin: boolean; keepSearch?: boolean }) => {
setGlobalWarnings([]);
setSearchParams({});
if (params?.toOrigin && origin) {
if (!keepSearch) {
setSearchParams({});
}
if (toOrigin && origin) {
navigate(origin);
} else {
dispatch(WizardAction.BACK);
Expand All @@ -166,6 +176,15 @@ const Wizard = ({
const steps = filteredChildren.map((child: WizardChildren) => {
const isLoading = wizardStepData[child.type.name]?.isLoading || false;
const hasError = wizardStepData[child.type.name]?.hasError;
const {
props: {
showNPS = true,
confirm = {
startOver: true,
startOverText: "Start Over",
},
},
} = child;

return (
<>
Expand All @@ -180,15 +199,17 @@ const Wizard = ({
<Grid container justifyContent="center">
{((state.activeStep === lastStepIndex && !isLoading) || hasError) && (
<>
<SimpleFeatureFlag feature="npsWizard">
<FeatureOn>
<NPSWizard />
</FeatureOn>
</SimpleFeatureFlag>
{(isMultistep || hasError) && (
{showNPS && (
<SimpleFeatureFlag feature="npsWizard">
<FeatureOn>
<NPSWizard />
</FeatureOn>
</SimpleFeatureFlag>
)}
{(isMultistep || hasError) && confirm.startOver && (
<ButtonGroup>
<Button
text="Start Over"
text={confirm.startOverText ?? "Start Over"}
onClick={() => {
dataLayoutManager.reset();
setSearchParams({});
Expand Down Expand Up @@ -216,7 +237,11 @@ const Wizard = ({
<MaxHeightGrid container alignItems="stretch" spacing={2}>
{heading && (
<Header item $orientation={orientation}>
<Typography variant="h2">{heading}</Typography>
{React.isValidElement(heading) ? (
heading
) : (
<Typography variant="h2">{heading}</Typography>
)}
</Header>
)}
<MaxHeightGrid
Expand Down

0 comments on commit 6c719a3

Please sign in to comment.