mirror of
https://github.com/hazemKrimi/crimson-quirks-ui.git
synced 2026-05-02 02:30:29 +00:00
Complete add feature
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
|||||||
Alert,
|
Alert,
|
||||||
TextArea,
|
TextArea,
|
||||||
CheckBox,
|
CheckBox,
|
||||||
|
ImagePreview,
|
||||||
} from '../../components';
|
} from '../../components';
|
||||||
import { Wrapper } from './styles';
|
import { Wrapper } from './styles';
|
||||||
import { ArrowLeft, General, Design } from '../../assets';
|
import { ArrowLeft, General, Design } from '../../assets';
|
||||||
@@ -39,7 +40,17 @@ const AddFeature = () => {
|
|||||||
}>;
|
}>;
|
||||||
price: number;
|
price: number;
|
||||||
repo: string;
|
repo: string;
|
||||||
}>();
|
}>({
|
||||||
|
name: '',
|
||||||
|
description: '',
|
||||||
|
featureType: '',
|
||||||
|
image: {
|
||||||
|
name: '',
|
||||||
|
src: '',
|
||||||
|
},
|
||||||
|
price: 0,
|
||||||
|
repo: '',
|
||||||
|
});
|
||||||
|
|
||||||
const [selectedSection, setSelectedSection] = useState<
|
const [selectedSection, setSelectedSection] = useState<
|
||||||
'general' | 'wireframes'
|
'general' | 'wireframes'
|
||||||
@@ -100,6 +111,17 @@ const AddFeature = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const wireframesForm = useFormik<{
|
||||||
|
wireframes: Array<{ name: string; src: string }>;
|
||||||
|
}>({
|
||||||
|
initialValues: {
|
||||||
|
wireframes: [],
|
||||||
|
},
|
||||||
|
onSubmit: ({ wireframes }) => {
|
||||||
|
addFeature({ variables: { feature: { ...newFeature, wireframes } } });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
return role === 'developer' ? (
|
return role === 'developer' ? (
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
<Box>
|
<Box>
|
||||||
@@ -125,14 +147,13 @@ const AddFeature = () => {
|
|||||||
icon={<General />}
|
icon={<General />}
|
||||||
color={role || 'client'}
|
color={role || 'client'}
|
||||||
text='General'
|
text='General'
|
||||||
selected
|
selected={selectedSection === 'general'}
|
||||||
/>
|
/>
|
||||||
<SectionSelector
|
<SectionSelector
|
||||||
icon={<Design />}
|
icon={<Design />}
|
||||||
color={role || 'client'}
|
color={role || 'client'}
|
||||||
text='Wireframes'
|
text='Wireframes'
|
||||||
selected={selectedSection === 'wireframes'}
|
selected={selectedSection === 'wireframes'}
|
||||||
onClick={() => setSelectedSection('wireframes')}
|
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
<Box
|
<Box
|
||||||
@@ -142,6 +163,8 @@ const AddFeature = () => {
|
|||||||
width='100%'
|
width='100%'
|
||||||
padding='30px'
|
padding='30px'
|
||||||
>
|
>
|
||||||
|
{selectedSection === 'general' && (
|
||||||
|
<>
|
||||||
<Box
|
<Box
|
||||||
display='grid'
|
display='grid'
|
||||||
gridTemplateColumns='auto 1fr'
|
gridTemplateColumns='auto 1fr'
|
||||||
@@ -150,12 +173,10 @@ const AddFeature = () => {
|
|||||||
marginBottom='50px'
|
marginBottom='50px'
|
||||||
>
|
>
|
||||||
<Text variant='subheader' weight='bold'>
|
<Text variant='subheader' weight='bold'>
|
||||||
General
|
{selectedSection === 'general' ? 'General' : 'Wireframes'}
|
||||||
</Text>
|
</Text>
|
||||||
{error && <Alert color='error' text={error} />}
|
{error && <Alert color='error' text={error} />}
|
||||||
</Box>
|
</Box>
|
||||||
{selectedSection === 'general' && (
|
|
||||||
<>
|
|
||||||
<form onSubmit={generalForm.handleSubmit}>
|
<form onSubmit={generalForm.handleSubmit}>
|
||||||
<Box
|
<Box
|
||||||
display='grid'
|
display='grid'
|
||||||
@@ -209,8 +230,9 @@ const AddFeature = () => {
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
error={
|
error={
|
||||||
!!generalForm.errors.imageName ||
|
generalForm.touched.imageName &&
|
||||||
!!generalForm.errors.imageSource
|
(!!generalForm.errors.imageName ||
|
||||||
|
!!generalForm.errors.imageSource)
|
||||||
}
|
}
|
||||||
errorMessage={generalForm.errors.imageName}
|
errorMessage={generalForm.errors.imageName}
|
||||||
/>
|
/>
|
||||||
@@ -230,7 +252,8 @@ const AddFeature = () => {
|
|||||||
Type
|
Type
|
||||||
</Text>
|
</Text>
|
||||||
</Box>
|
</Box>
|
||||||
{!!generalForm.errors.featureType && (
|
{!!generalForm.touched.featureType &&
|
||||||
|
generalForm.errors.featureType && (
|
||||||
<Box justifySelf='flex-end'>
|
<Box justifySelf='flex-end'>
|
||||||
<Text variant='body' color='error'>
|
<Text variant='body' color='error'>
|
||||||
{generalForm.errors.featureType}
|
{generalForm.errors.featureType}
|
||||||
@@ -370,6 +393,87 @@ const AddFeature = () => {
|
|||||||
</form>
|
</form>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
{selectedSection === 'wireframes' && (
|
||||||
|
<>
|
||||||
|
<Box
|
||||||
|
display='grid'
|
||||||
|
gridTemplateColumns='auto 1fr'
|
||||||
|
columnGap='1rem'
|
||||||
|
alignItems='center'
|
||||||
|
marginBottom='50px'
|
||||||
|
>
|
||||||
|
<Text variant='subheader' weight='bold'>
|
||||||
|
Wireframes
|
||||||
|
</Text>
|
||||||
|
{error && <Alert color='error' text={error} />}
|
||||||
|
</Box>
|
||||||
|
<form onSubmit={wireframesForm.handleSubmit}>
|
||||||
|
<Box
|
||||||
|
display='grid'
|
||||||
|
gridTemplate='auto / repeat(auto-fit, 175px)'
|
||||||
|
gap='30px'
|
||||||
|
alignItems='stretch'
|
||||||
|
>
|
||||||
|
<ImagePreview
|
||||||
|
color={role}
|
||||||
|
image={undefined}
|
||||||
|
onChange={async (
|
||||||
|
event: React.ChangeEvent<HTMLInputElement>
|
||||||
|
) => {
|
||||||
|
const formData = new FormData();
|
||||||
|
|
||||||
|
if (event.target.files && event.target.files[0]) {
|
||||||
|
formData.append('file', event.target.files[0]);
|
||||||
|
formData.append('upload_preset', 'xofll5kc');
|
||||||
|
|
||||||
|
const data = await (
|
||||||
|
await fetch(
|
||||||
|
`${process.env.REACT_APP_CLOUDINARY_URL}`,
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
body: formData,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
).json();
|
||||||
|
|
||||||
|
const filename = data.original_filename;
|
||||||
|
const filesource = data.secure_url;
|
||||||
|
|
||||||
|
wireframesForm.setFieldValue('wireframes', [
|
||||||
|
...wireframesForm.values.wireframes,
|
||||||
|
{ name: filename, src: filesource },
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{wireframesForm.values.wireframes.map((image) => (
|
||||||
|
<ImagePreview
|
||||||
|
key={image.name}
|
||||||
|
color={role}
|
||||||
|
image={image}
|
||||||
|
onDelete={() => {
|
||||||
|
wireframesForm.setFieldValue(
|
||||||
|
'wireframes',
|
||||||
|
wireframesForm.values.wireframes.filter(
|
||||||
|
({ name }) => name !== image.name
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Box>
|
||||||
|
<Box marginTop='1rem' display='flex' justifyContent='flex-end'>
|
||||||
|
<Button
|
||||||
|
variant='primary-action'
|
||||||
|
color={role || 'client'}
|
||||||
|
text='Save'
|
||||||
|
type='submit'
|
||||||
|
loading={loading}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</form>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user