Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

15 create new campaign page #31

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 23 additions & 28 deletions components/CreateNewCampaign/MultipleFileUploadField.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Grid, Typography } from '@mui/material';
import { Grid, Button, Typography, Stack } from '@mui/material';
import { useField } from 'formik';
import React, { useCallback, useEffect, useState } from 'react';
import { FileError, FileRejection, useDropzone } from 'react-dropzone';
import SingleFileUploadWithProgress from './SingleFileUploadWithProgress';
import { UploadError } from './UploadError';

// import { makeStyles } from '@mui/styles';
import { createTheme, ThemeProvider } from '@mui/material/styles';

let currentId = 0;
Expand All @@ -23,31 +22,8 @@ export interface UploadableFile {

const theme = createTheme();
lihuicham marked this conversation as resolved.
Show resolved Hide resolved

// const useStyles = makeStyles((theme) => ({
// dropzone: {
// border: `2px dashed ${theme.palette.primary.main}`,
// borderRadius: theme.shape.borderRadius,
// display: 'flex',
// alignItems: 'center',
// justifyContent: 'center',
// background: theme.palette.background.default,
// height: theme.spacing(10),
// outline: 'none',
// },
// }));

const styledTypo = {
textAlign: 'center',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}


const MultipleFileUploadField = ({ name }: { name: string }) => {
const [_, __, helpers] = useField(name);
// const classes = useStyles();

const [files, setFiles] = useState<UploadableFile[]>([]);
const onDrop = useCallback((accFiles: File[], rejFiles: FileRejection[]) => {
const mappedAcc = accFiles.map((file) => ({ file, errors: [], id: getNewId() }));
Expand All @@ -57,7 +33,6 @@ const MultipleFileUploadField = ({ name }: { name: string }) => {

useEffect(() => {
helpers.setValue(files);
// helpers.setTouched(true);
}, [files]);

function onUpload(file: File, url: string) {
Expand Down Expand Up @@ -89,8 +64,11 @@ const MultipleFileUploadField = ({ name }: { name: string }) => {
<Grid item>
<div {...getRootProps()}>
<input {...getInputProps()} />
<Typography sx={styledTypo}>Click to upload or drag and drop</Typography>
<Typography sx={styledTypo}>PNG, GIF, JPEG, JPG or SVG files - max 3MB</Typography>
<Stack sx={styledStack}>
<Button variant="contained" sx={styledButton}>Click to upload or drag and drop</Button>
<Typography sx={styledTypo}>PNG, GIF, JPEG, JPG or SVG files - max 3MB</Typography>
</Stack>

</div>
</Grid>

Expand All @@ -117,5 +95,22 @@ const MultipleFileUploadField = ({ name }: { name: string }) => {
);
}

const styledStack = {
display: 'flex',
justifyContent: 'center',
}

const styledTypo = {
textAlign: 'center',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
fontSize: '15px',
marginTop: '10px'
}

const styledButton = {
padding: '20px',
}

export default MultipleFileUploadField;
14 changes: 12 additions & 2 deletions components/CreateNewCampaign/SingleFileUploadWithProgress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const SingleFileUploadWithProgress = ({
}, []);

return (
<Grid item>
<Grid item sx={styledGrid}>
<FileHeader file={file} onDelete={onDelete} />
<LinearProgress variant="determinate" value={progress} />
<LinearProgress variant="determinate" value={progress} sx={styledProgress}/>
</Grid>
);
}
Expand Down Expand Up @@ -60,4 +60,14 @@ function uploadFile(file: File, onProgress: (percentage: number) => void) {
});
}

const styledProgress = {
width: '100%',
}

const styledGrid = {
marginLeft: '20px',
marginRight: '20px',
marginTop: '10px'
}

export default SingleFileUploadWithProgress;
8 changes: 0 additions & 8 deletions components/CreateNewCampaign/UploadError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ import {
errors: FileError[];
}

// const ErrorLinearProgress = withStyles((theme) =>
// createStyles({
// bar: {
// backgroundColor: theme.palette.error.main,
// },
// })
// )(LinearProgress);

export function UploadError({ file, onDelete, errors }: UploadErrorProps) {
return (
<React.Fragment>
Expand Down
72 changes: 31 additions & 41 deletions components/CreateNewCampaign/UploadMedia.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,41 @@
import { Button, Card, CardContent, Grid } from '@mui/material';
import { Card, Grid } from '@mui/material';
import { Form, Formik } from 'formik';
import React from 'react';
import { array, object, string } from 'yup';
import MultipleFileUploadField from './MultipleFileUploadField';

const UploadMedia = () => {
return (
<Card>
<CardContent>
<Formik
initialValues={{ files: [] }}
validationSchema={object({
files: array(
object({
url: string().required(),
})
),
})}
onSubmit={(values) => {
console.log('values', values);
return new Promise((res) => setTimeout(res, 2000));
}}
>
{({isValid, isSubmitting }) => (
<Form>
<Grid container spacing={2} direction="column" sx={{height: '100%'}}>
<MultipleFileUploadField name="files" />

<Grid item>
<Button
variant="contained"
color="primary"
disabled={!isValid || isSubmitting}
type="submit"
sx={{marginTop: '10px'}}
>
Submit
</Button>
</Grid>
</Grid>
</Form>
)}
</Formik>
</CardContent>
</Card>
);
<Formik
initialValues={{ files: [] }}
validationSchema={object({
files: array(
object({
url: string().required(),
})
),
})}
onSubmit={(values) => {
console.log('values', values)
return new Promise((res) => setTimeout(res, 2000))
}}
>
{() => (
<Form>
<Card style={styledCard}>
<Grid container spacing={2} direction="column">
<MultipleFileUploadField name="files" />
</Grid>
</Card>
</Form>
)}
</Formik>
)
}

export default UploadMedia;
const styledCard = {
minHeight: '140px',
overflow: 'scroll',
}

export default UploadMedia
92 changes: 0 additions & 92 deletions components/CreateNewCampaign/index.tsx

This file was deleted.

13 changes: 0 additions & 13 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
import type { AppProps } from 'next/app'
import Layout from 'components/Layout'
import CreateNewCampaign from 'components/CreateNewCampaign'

/*
function MyApp({ Component, pageProps }: AppProps) {
return (
<Layout>
<Component {...pageProps} />
</Layout>
)
}

export default MyApp
*/

function MyApp({ Component, pageProps }: AppProps) {
return (
<Layout>
<Component {...pageProps} />
<CreateNewCampaign />
</Layout>
)
}
Expand Down
Loading