From a5f47eb238d6c7cfe875e46a1bb46f1ab57f7f00 Mon Sep 17 00:00:00 2001 From: Brent Date: Tue, 26 Sep 2023 17:16:06 -0400 Subject: [PATCH] incomplete updates --- .../EditForm/ProgressReportEdit.graphql | 30 +------- .../EditForm/Steps/Media/MediaInfoForm.tsx | 71 +++++++++---------- .../EditForm/Steps/Media/MediaStep.graphql | 34 ++++----- .../EditForm/Steps/Media/MediaStep.tsx | 15 ++-- .../Steps/Media/VariantMediaAccordion.tsx | 27 ++++--- .../Steps/Media/progressReportMedia.graphql | 23 ++++++ 6 files changed, 93 insertions(+), 107 deletions(-) create mode 100644 src/scenes/ProgressReports/EditForm/Steps/Media/progressReportMedia.graphql diff --git a/src/scenes/ProgressReports/EditForm/ProgressReportEdit.graphql b/src/scenes/ProgressReports/EditForm/ProgressReportEdit.graphql index 0a17cdbdf6..364e8ecab7 100644 --- a/src/scenes/ProgressReports/EditForm/ProgressReportEdit.graphql +++ b/src/scenes/ProgressReports/EditForm/ProgressReportEdit.graphql @@ -22,35 +22,7 @@ fragment ProgressReportEdit on ProgressReport { progressForAllVariants { ...ProgressReportProgress } - media { - items { - variant { - key - label - responsibleRole - } - variantGroup - id - category - media { - altText - caption - file { - id - url - name - mimeType - type - size - } - } - } - uploadableVariants { - key - label - responsibleRole - } - } + ...mediaStep status { ...ProgressReportStatus } diff --git a/src/scenes/ProgressReports/EditForm/Steps/Media/MediaInfoForm.tsx b/src/scenes/ProgressReports/EditForm/Steps/Media/MediaInfoForm.tsx index 2c2ea83266..ae8e5e2f2e 100644 --- a/src/scenes/ProgressReports/EditForm/Steps/Media/MediaInfoForm.tsx +++ b/src/scenes/ProgressReports/EditForm/Steps/Media/MediaInfoForm.tsx @@ -5,46 +5,41 @@ import { ProgressReportMediaCategoryList, } from '~/api/schema/enumLists'; import { labelFrom } from '~/common'; -import { Form, SelectField } from '~/components/form'; +import { Form, FormProps, SelectField } from '~/components/form'; -export const MediaInfoForm = ({ - disabled, - initialValues, -}: { - disabled: boolean; - initialValues: { - category: ProgressReportMediaCategory | null; - caption: string | null; - id: string; - }; -}) => { +export interface MediaFormState { + category: ProgressReportMediaCategory | null; + caption: string | null; + id?: string; +} +export const MediaInfoForm = ({ ...formValues }: FormProps) => { return ( -
{ - // placeholder for submit logic - }} - > - - - - + {...formValues}> + {({ handleSubmit, values }) => ( + + + + + )} ); }; diff --git a/src/scenes/ProgressReports/EditForm/Steps/Media/MediaStep.graphql b/src/scenes/ProgressReports/EditForm/Steps/Media/MediaStep.graphql index 488f951260..ae8a4fa65a 100644 --- a/src/scenes/ProgressReports/EditForm/Steps/Media/MediaStep.graphql +++ b/src/scenes/ProgressReports/EditForm/Steps/Media/MediaStep.graphql @@ -1,34 +1,28 @@ mutation CreateMedia($input: UploadProgressReportMedia!) { uploadProgressReportMedia(input: $input) { - id - media { - items { - id - variant { - ...variant - } - category - } - } + ...mediaStep } } mutation UpdateMedia($input: UpdateProgressReportMedia!) { updateProgressReportMedia(input: $input) { - id - media { - altText - caption - id - mimeType - url - } + ...progressReportMedia } } mutation DeleteMedia($deleteProgressReportMediaId: ID!) { deleteProgressReportMedia(id: $deleteProgressReportMediaId) { - parent { - id + ...mediaStep + } +} + +fragment mediaStep on ProgressReport { + id + media { + items { + ...progressReportMedia + } + uploadableVariants { + ...variant } } } diff --git a/src/scenes/ProgressReports/EditForm/Steps/Media/MediaStep.tsx b/src/scenes/ProgressReports/EditForm/Steps/Media/MediaStep.tsx index 240782db57..046f895e53 100644 --- a/src/scenes/ProgressReports/EditForm/Steps/Media/MediaStep.tsx +++ b/src/scenes/ProgressReports/EditForm/Steps/Media/MediaStep.tsx @@ -7,6 +7,8 @@ import { DropOverlay } from '~/components/Upload/DropOverlay'; import { StepComponent } from '../step.types'; import { CreateMediaDocument, DeleteMediaDocument } from './MediaStep.graphql'; import { VariantMediaAccordion } from './VariantMediaAccordion'; +import { FormProps } from "~/components/form"; +import { MediaFormState } from "~/scenes/ProgressReports/EditForm/Steps/Media/MediaInfoForm"; // TODO find types for actual uploadVariant here export interface MediaVariantResponse { @@ -18,8 +20,10 @@ export const MediaStep: StepComponent = ({ report }) => { const [deleteMedia] = useMutation(DeleteMediaDocument); const uploadFile = useUploadFileAsync(); - const handleFileUpload = async (files: File[]) => { - const [uploadedImageInfo, finalizeUpload] = await uploadFile(files[0]); + const handleSubmit: FormProps["onSubmit"] = async (values) => { + // use values.id to determine if we want to create, update, delete + // delete = values.id + submitAction + const [uploadedImageInfo, finalizeUpload] = await uploadFile(values); if (!uploadedImageInfo) { finalizeUpload.tap; return; @@ -59,13 +63,6 @@ export const MediaStep: StepComponent = ({ report }) => { .map((variant) => { return ( - - Drop files to start uploading - - { const [expanded, setExpanded] = useState(initiallyOpen); + const initialValues = useMemo( + () => + existingMedia + ? { + category: existingMedia.category, + caption: existingMedia.media.caption, + id: existingMedia.id, + } + : undefined, + [existingMedia] + ); const deleteCurrentMedia = useCallback(async () => { await deleteMedia({ variables: { deleteProgressReportMediaId: response.item[0]?.id }, @@ -272,14 +284,7 @@ export const VariantMediaAccordion = ({ deleteMedia={deleteCurrentMedia} sensitivity={sensitivity} /> - + ); diff --git a/src/scenes/ProgressReports/EditForm/Steps/Media/progressReportMedia.graphql b/src/scenes/ProgressReports/EditForm/Steps/Media/progressReportMedia.graphql new file mode 100644 index 0000000000..0d3f1deed9 --- /dev/null +++ b/src/scenes/ProgressReports/EditForm/Steps/Media/progressReportMedia.graphql @@ -0,0 +1,23 @@ +fragment progressReportMedia on ProgressReportMedia { + variant { + key + label + responsibleRole + } + variantGroup + id + category + media { + id + altText + caption + file { + id + url + name + mimeType + type + size + } + } +}