2023-01-03 15:30:59 +01:00
|
|
|
import { Button, styled } from '@mui/material';
|
2022-03-29 09:30:57 +02:00
|
|
|
import Input from 'component/common/Input/Input';
|
|
|
|
import React from 'react';
|
2022-05-05 13:42:18 +02:00
|
|
|
import { useNavigate } from 'react-router-dom';
|
2023-01-03 15:30:59 +01:00
|
|
|
import { SegmentFormStep } from './SegmentForm';
|
2022-04-08 12:34:59 +02:00
|
|
|
import {
|
|
|
|
SEGMENT_NAME_ID,
|
|
|
|
SEGMENT_DESC_ID,
|
|
|
|
SEGMENT_NEXT_BTN_ID,
|
|
|
|
} from 'utils/testIds';
|
2022-03-29 09:30:57 +02:00
|
|
|
|
|
|
|
interface ISegmentFormPartOneProps {
|
|
|
|
name: string;
|
|
|
|
description: string;
|
|
|
|
setName: React.Dispatch<React.SetStateAction<string>>;
|
|
|
|
setDescription: React.Dispatch<React.SetStateAction<string>>;
|
|
|
|
errors: { [key: string]: string };
|
|
|
|
clearErrors: () => void;
|
|
|
|
setCurrentStep: React.Dispatch<React.SetStateAction<SegmentFormStep>>;
|
|
|
|
}
|
|
|
|
|
2023-01-03 15:30:59 +01:00
|
|
|
const StyledForm = styled('div')(({ theme }) => ({
|
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'column',
|
|
|
|
height: '100%',
|
|
|
|
}));
|
|
|
|
|
|
|
|
const StyledContainer = styled('div')(({ theme }) => ({
|
|
|
|
maxWidth: '400px',
|
|
|
|
}));
|
|
|
|
|
|
|
|
const StyledInputDescription = styled('p')(({ theme }) => ({
|
|
|
|
marginBottom: theme.spacing(1),
|
|
|
|
}));
|
|
|
|
|
|
|
|
const StyledInput = styled(Input)(({ theme }) => ({
|
|
|
|
width: '100%',
|
|
|
|
marginBottom: theme.spacing(2),
|
|
|
|
}));
|
|
|
|
|
|
|
|
const StyledButtonContainer = styled('div')(({ theme }) => ({
|
|
|
|
marginTop: 'auto',
|
|
|
|
display: 'flex',
|
|
|
|
justifyContent: 'flex-end',
|
|
|
|
}));
|
|
|
|
|
|
|
|
const StyledCancelButton = styled(Button)(({ theme }) => ({
|
|
|
|
marginLeft: theme.spacing(3),
|
|
|
|
}));
|
|
|
|
|
2022-03-29 09:30:57 +02:00
|
|
|
export const SegmentFormStepOne: React.FC<ISegmentFormPartOneProps> = ({
|
|
|
|
children,
|
|
|
|
name,
|
|
|
|
description,
|
|
|
|
setName,
|
|
|
|
setDescription,
|
|
|
|
errors,
|
|
|
|
clearErrors,
|
|
|
|
setCurrentStep,
|
|
|
|
}) => {
|
2022-05-05 13:42:18 +02:00
|
|
|
const navigate = useNavigate();
|
2022-03-29 09:30:57 +02:00
|
|
|
|
|
|
|
return (
|
2023-01-03 15:30:59 +01:00
|
|
|
<StyledForm>
|
|
|
|
<StyledContainer>
|
|
|
|
<StyledInputDescription>
|
2022-03-29 09:30:57 +02:00
|
|
|
What is the segment name?
|
2023-01-03 15:30:59 +01:00
|
|
|
</StyledInputDescription>
|
|
|
|
<StyledInput
|
2022-03-29 09:30:57 +02:00
|
|
|
label="Segment name"
|
|
|
|
value={name}
|
|
|
|
onChange={e => setName(e.target.value)}
|
|
|
|
error={Boolean(errors.name)}
|
|
|
|
errorText={errors.name}
|
|
|
|
autoFocus
|
|
|
|
required
|
2022-04-08 13:13:45 +02:00
|
|
|
data-testid={SEGMENT_NAME_ID}
|
2022-03-29 09:30:57 +02:00
|
|
|
/>
|
2023-01-03 15:30:59 +01:00
|
|
|
<StyledInputDescription>
|
2022-03-29 09:30:57 +02:00
|
|
|
What is the segment description?
|
2023-01-03 15:30:59 +01:00
|
|
|
</StyledInputDescription>
|
|
|
|
<StyledInput
|
2022-03-29 09:30:57 +02:00
|
|
|
label="Description (optional)"
|
|
|
|
value={description}
|
|
|
|
onChange={e => setDescription(e.target.value)}
|
|
|
|
error={Boolean(errors.description)}
|
|
|
|
errorText={errors.description}
|
2022-04-08 13:13:45 +02:00
|
|
|
data-testid={SEGMENT_DESC_ID}
|
2022-03-29 09:30:57 +02:00
|
|
|
/>
|
2023-01-03 15:30:59 +01:00
|
|
|
</StyledContainer>
|
|
|
|
<StyledButtonContainer>
|
2022-03-29 09:30:57 +02:00
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
variant="contained"
|
|
|
|
color="primary"
|
|
|
|
onClick={() => setCurrentStep(2)}
|
2022-04-08 12:34:59 +02:00
|
|
|
disabled={name.length === 0 || Boolean(errors.name)}
|
2022-04-08 13:13:45 +02:00
|
|
|
data-testid={SEGMENT_NEXT_BTN_ID}
|
2022-03-29 09:30:57 +02:00
|
|
|
>
|
|
|
|
Next
|
|
|
|
</Button>
|
2023-01-03 15:30:59 +01:00
|
|
|
<StyledCancelButton
|
2022-03-29 09:30:57 +02:00
|
|
|
type="button"
|
|
|
|
onClick={() => {
|
2022-05-05 13:42:18 +02:00
|
|
|
navigate('/segments');
|
2022-03-29 09:30:57 +02:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
Cancel
|
2023-01-03 15:30:59 +01:00
|
|
|
</StyledCancelButton>
|
|
|
|
</StyledButtonContainer>
|
|
|
|
</StyledForm>
|
2022-03-29 09:30:57 +02:00
|
|
|
);
|
|
|
|
};
|