2022-05-02 15:52:41 +02:00
|
|
|
import { Button } 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';
|
2022-03-29 09:30:57 +02:00
|
|
|
import { useStyles } from 'component/segments/SegmentFormStepOne/SegmentFormStepOne.styles';
|
|
|
|
import { SegmentFormStep } from '../SegmentForm/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>>;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-05-02 15:52:41 +02:00
|
|
|
const { classes: styles } = useStyles();
|
2022-03-29 09:30:57 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.form}>
|
|
|
|
<div className={styles.container}>
|
|
|
|
<p className={styles.inputDescription}>
|
|
|
|
What is the segment name?
|
|
|
|
</p>
|
|
|
|
<Input
|
|
|
|
className={styles.input}
|
|
|
|
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
|
|
|
/>
|
|
|
|
<p className={styles.inputDescription}>
|
|
|
|
What is the segment description?
|
|
|
|
</p>
|
|
|
|
<Input
|
|
|
|
className={styles.input}
|
|
|
|
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
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className={styles.buttonContainer}>
|
|
|
|
<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>
|
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
className={styles.cancelButton}
|
|
|
|
onClick={() => {
|
2022-05-05 13:42:18 +02:00
|
|
|
navigate('/segments');
|
2022-03-29 09:30:57 +02:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
Cancel
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|