Skip to content

Commit

Permalink
pulls out the update logic for now
Browse files Browse the repository at this point in the history
  • Loading branch information
brentkulwicki committed Sep 26, 2023
1 parent 96b5520 commit c3dede7
Show file tree
Hide file tree
Showing 4 changed files with 217 additions and 42 deletions.
28 changes: 10 additions & 18 deletions src/scenes/ProgressReports/EditForm/Steps/Media/MediaInfoForm.tsx
Original file line number Diff line number Diff line change
@@ -1,52 +1,44 @@
import { Box, TextField } from '@mui/material';
import { ProgressReportMediaCategory } from '~/api/schema.graphql';
import {
ProgressReportMediaCategoryLabels,
ProgressReportMediaCategoryList,
} from '~/api/schema/enumLists';
import { labelFrom } from '~/common';
import { Form, SelectField } from '~/components/form';
import { minLength, required } from '~/components/form/validators';
import { useCallback, useState } from 'react';
import { ProgressReportMediaCategory } from '~/api/schema.graphql';

// TODO type submitForm
// @ts-ignore
export const MediaInfoForm = ({
submitForm,
disabled,
initialValues,
}: {
submitForm: any;
disabled: boolean;
initialValues: {
category: ProgressReportMediaCategory | null;
caption: string | null;
id: string;
};
}) => {
const [category, setCategory] = useState(initialValues.category);
const [caption, setCaption] = useState(initialValues.caption);
const updateMedia = useCallback(() => {
submitForm({ variables: {} });
}, []);
return (
<Form onSubmit={submitForm}>
<Form
onSubmit={() => {
// placeholder for submit logic
}}
>
<Box sx={{ p: 1, m: 1, flexGrow: 2 }}>
<SelectField
label="Photo Category"
name="category"
disabled={disabled}
disabled={true}
options={ProgressReportMediaCategoryList}
variant="outlined"
getOptionLabel={labelFrom(ProgressReportMediaCategoryLabels)}
defaultValue={
disabled ? null : category || ProgressReportMediaCategoryList[0]
}
defaultValue={disabled ? null : ProgressReportMediaCategoryList[0]}
/>
<TextField
variant="outlined"
name="caption"
label="Caption"
disabled={disabled}
disabled={true}
placeholder="Enter Photo Caption"
minRows={4}
margin="none"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@ mutation UpdateMedia($input: UpdateProgressReportMedia!) {
}
}
}
# placeholder for delete
# placeholder for download
mutation DeleteMedia($deleteProgressReportMediaId: ID!) {
deleteProgressReportMedia(id: $deleteProgressReportMediaId) {
parent {
id
}
}
}
15 changes: 5 additions & 10 deletions src/scenes/ProgressReports/EditForm/Steps/Media/MediaStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useDropzone } from 'react-dropzone';
import { useUploadFileAsync } from '~/components/files/hooks';
import { DropOverlay } from '~/components/Upload/DropOverlay';
import { StepComponent } from '../step.types';
import { CreateMediaDocument, UpdateMediaDocument } from './MediaStep.graphql';
import { CreateMediaDocument, DeleteMediaDocument } from './MediaStep.graphql';
import { VariantMediaAccordion } from './VariantMediaAccordion';

// TODO find types for actual uploadVariant here
Expand All @@ -15,11 +15,9 @@ export interface MediaVariantResponse {
}
export const MediaStep: StepComponent = ({ report }) => {
const [createMedia] = useMutation(CreateMediaDocument);
const [updateMedia] = useMutation(UpdateMediaDocument);
const [deleteMedia] = useMutation(DeleteMediaDocument);
const uploadFile = useUploadFileAsync();

// TODO remove this before going live
console.log(report);
const handleFileUpload = async (files: File[]) => {
const [uploadedImageInfo, finalizeUpload] = await uploadFile(files[0]);
if (!uploadedImageInfo) {
Expand All @@ -35,8 +33,8 @@ export const MediaStep: StepComponent = ({ report }) => {
},
},
}).then(...finalizeUpload.tap);
// finalizeUpload.tap;
};

const {
getRootProps,
getInputProps,
Expand All @@ -49,10 +47,6 @@ export const MediaStep: StepComponent = ({ report }) => {
disabled: false,
});

const chooseFileAndUpload = () => {
const file = openFileBrowser();
console.log(file);
};
return (
<div {...getRootProps()}>
<Box sx={{ maxWidth: 'md' }}>
Expand All @@ -74,14 +68,15 @@ export const MediaStep: StepComponent = ({ report }) => {
/>
<Box sx={{ display: 'block' }} key={variant.key}>
<VariantMediaAccordion
updateMedia={updateMedia}
deleteMedia={deleteMedia}
openFileBrowser={openFileBrowser}
response={{
item: report.media.items.filter(
(item) => item.variant.key === variant.key
),
uploadVariant: variant,
}}
sensitivity={report.parent.sensitivity}
initiallyOpen={false}
/>
</Box>
Expand Down
Loading

0 comments on commit c3dede7

Please sign in to comment.