mirror of
https://github.com/hazemKrimi/crimson-quirks-ui.git
synced 2026-05-01 18:20:28 +00:00
Complete feature settings
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
|||||||
Spinner,
|
Spinner,
|
||||||
Modal,
|
Modal,
|
||||||
CheckBox,
|
CheckBox,
|
||||||
|
ImagePreview,
|
||||||
} from '../../components';
|
} from '../../components';
|
||||||
import { Wrapper } from './styles';
|
import { Wrapper } from './styles';
|
||||||
import { ArrowLeft, Design, General } from '../../assets';
|
import { ArrowLeft, Design, General } from '../../assets';
|
||||||
@@ -43,7 +44,18 @@ const FeatureSettings = () => {
|
|||||||
>('general');
|
>('general');
|
||||||
const [error, setError] = useState<string>('');
|
const [error, setError] = useState<string>('');
|
||||||
const [success, setSuccess] = useState<boolean>(false);
|
const [success, setSuccess] = useState<boolean>(false);
|
||||||
const [feature, setFeature] = useState<FeatureOutput>();
|
const [feature, setFeature] = useState<FeatureOutput>({
|
||||||
|
id,
|
||||||
|
name: '',
|
||||||
|
description: '',
|
||||||
|
featureType: '',
|
||||||
|
image: {
|
||||||
|
name: '',
|
||||||
|
src: '',
|
||||||
|
},
|
||||||
|
price: 0,
|
||||||
|
repo: '',
|
||||||
|
});
|
||||||
|
|
||||||
const [deleteFeatureModal, setDeleteFeatureModal] = useState<boolean>(false);
|
const [deleteFeatureModal, setDeleteFeatureModal] = useState<boolean>(false);
|
||||||
|
|
||||||
@@ -137,6 +149,35 @@ const FeatureSettings = () => {
|
|||||||
enableReinitialize: true,
|
enableReinitialize: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const wireframesForm = useFormik<{
|
||||||
|
wireframes: Array<{ name: string; src: string }>;
|
||||||
|
}>({
|
||||||
|
initialValues: {
|
||||||
|
wireframes:
|
||||||
|
feature?.wireframes?.map((wireframe) => ({
|
||||||
|
name: wireframe.name,
|
||||||
|
src: wireframe.src,
|
||||||
|
})) || [],
|
||||||
|
},
|
||||||
|
onSubmit: ({ wireframes }) => {
|
||||||
|
updateFeature({
|
||||||
|
variables: {
|
||||||
|
id,
|
||||||
|
feature: {
|
||||||
|
name: feature.name,
|
||||||
|
description: feature.description,
|
||||||
|
price: feature.price,
|
||||||
|
repo: feature.repo,
|
||||||
|
featureType: feature.featureType,
|
||||||
|
image: { name: feature.image.name, src: feature.image.src },
|
||||||
|
wireframes,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
enableReinitialize: true,
|
||||||
|
});
|
||||||
|
|
||||||
return role === 'developer' ? (
|
return role === 'developer' ? (
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
<Box>
|
<Box>
|
||||||
@@ -162,7 +203,8 @@ const FeatureSettings = () => {
|
|||||||
icon={<General />}
|
icon={<General />}
|
||||||
color={role || 'client'}
|
color={role || 'client'}
|
||||||
text='General'
|
text='General'
|
||||||
selected
|
selected={selectedSection === 'general'}
|
||||||
|
onClick={() => setSelectedSection('general')}
|
||||||
/>
|
/>
|
||||||
<SectionSelector
|
<SectionSelector
|
||||||
icon={<Design />}
|
icon={<Design />}
|
||||||
@@ -187,11 +229,11 @@ const FeatureSettings = () => {
|
|||||||
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} />}
|
||||||
{success && (
|
{success && (
|
||||||
<Alert color='success' text='Account updated successfully' />
|
<Alert color='success' text='Feature updated successfully' />
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
{selectedSection === 'general' && (
|
{selectedSection === 'general' && (
|
||||||
@@ -264,8 +306,9 @@ const FeatureSettings = () => {
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
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}
|
||||||
/>
|
/>
|
||||||
@@ -451,6 +494,70 @@ const FeatureSettings = () => {
|
|||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
{selectedSection === 'wireframes' && (
|
||||||
|
<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