From c3dede7c515d5c50c98b42a1d2588704c2a93cbe Mon Sep 17 00:00:00 2001 From: Brent Date: Tue, 26 Sep 2023 11:59:49 -0400 Subject: [PATCH] pulls out the update logic for now --- .../EditForm/Steps/Media/MediaInfoForm.tsx | 28 +-- .../EditForm/Steps/Media/MediaStep.graphql | 9 +- .../EditForm/Steps/Media/MediaStep.tsx | 15 +- .../Steps/Media/VariantMediaAccordion.tsx | 207 +++++++++++++++++- 4 files changed, 217 insertions(+), 42 deletions(-) diff --git a/src/scenes/ProgressReports/EditForm/Steps/Media/MediaInfoForm.tsx b/src/scenes/ProgressReports/EditForm/Steps/Media/MediaInfoForm.tsx index e48fffa0ab..2c2ea83266 100644 --- a/src/scenes/ProgressReports/EditForm/Steps/Media/MediaInfoForm.tsx +++ b/src/scenes/ProgressReports/EditForm/Steps/Media/MediaInfoForm.tsx @@ -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 ( -
+ { + // placeholder for submit logic + }} + > { 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) { @@ -35,8 +33,8 @@ export const MediaStep: StepComponent = ({ report }) => { }, }, }).then(...finalizeUpload.tap); - // finalizeUpload.tap; }; + const { getRootProps, getInputProps, @@ -49,10 +47,6 @@ export const MediaStep: StepComponent = ({ report }) => { disabled: false, }); - const chooseFileAndUpload = () => { - const file = openFileBrowser(); - console.log(file); - }; return (
@@ -74,7 +68,7 @@ export const MediaStep: StepComponent = ({ report }) => { /> { ), uploadVariant: variant, }} + sensitivity={report.parent.sensitivity} initiallyOpen={false} /> diff --git a/src/scenes/ProgressReports/EditForm/Steps/Media/VariantMediaAccordion.tsx b/src/scenes/ProgressReports/EditForm/Steps/Media/VariantMediaAccordion.tsx index b8dc587eab..a7a5dc8a04 100644 --- a/src/scenes/ProgressReports/EditForm/Steps/Media/VariantMediaAccordion.tsx +++ b/src/scenes/ProgressReports/EditForm/Steps/Media/VariantMediaAccordion.tsx @@ -1,39 +1,213 @@ -import { AddPhotoAlternate, ExpandMore } from '@mui/icons-material'; +import { + Add, + AddPhotoAlternate, + Delete, + ExpandMore, + GetApp, + MoreVert, + Publish, +} from '@mui/icons-material'; import { Accordion, AccordionDetails, AccordionSummary, Box, + Button, + ClickAwayListener, + Grow, IconButton, + Link, + MenuItem, + MenuList, + Paper, + Popper, + Stack, } from '@mui/material'; -import { useState } from 'react'; +import { + KeyboardEvent, + SyntheticEvent, + useCallback, + useEffect, + useRef, + useState, +} from 'react'; +import { Sensitivity as SensitivityType } from '~/api/schema/schema.graphql'; import { RoleIcon } from '~/components/RoleIcon'; +import { SensitivityIcon } from '~/components/Sensitivity'; import { MediaInfoForm } from './MediaInfoForm'; import { MediaVariantResponse } from './MediaStep'; +// TODO update types +const MoreActionsButton = ({ + uploadImage, + downloadUrl, + deleteImage, +}: { + uploadImage: any; + downloadUrl: string; + deleteImage: any; +}) => { + const [open, setOpen] = useState(false); + const anchorRef = useRef(null); + + const handleToggle = () => { + setOpen((prevOpen) => !prevOpen); + }; + + const handleClose = (event: Event | SyntheticEvent) => { + if ( + anchorRef.current && + anchorRef.current.contains(event.target as HTMLElement) + ) { + return; + } + + setOpen(false); + }; + + function handleListKeyDown(event: KeyboardEvent) { + if (event.key === 'Tab') { + event.preventDefault(); + setOpen(false); + } else if (event.key === 'Escape') { + setOpen(false); + } + } + + // return focus to the button when we transitioned from !open -> open + const prevOpen = useRef(open); + useEffect(() => { + if (prevOpen.current && !open) { + anchorRef.current!.focus(); + } + + prevOpen.current = open; + }, [open]); + + return ( + +
+ + + {({ TransitionProps, placement }) => ( + + + + + + + Download + + + + Upload Revised + + + Upload Alternate + + + Delete + + + + + + )} + +
+
+ ); +}; + const ImageBox = ({ media, + sensitivity, openFileBrowser, + deleteMedia, }: { media: any[]; + sensitivity: SensitivityType; openFileBrowser: any; + deleteMedia: any; }) => { return ( <> {media.length ? ( - // TODO replace with image when it exists - {media[0].media.altText} + + + + + + + {/* TODO - fix static nature of what file we are showing */} + ) : ( { const [expanded, setExpanded] = useState(initiallyOpen); - + const deleteCurrentMedia = useCallback(async () => { + await deleteMedia({ + variables: { deleteProgressReportMediaId: response.item[0]?.id }, + }); + }, [deleteMedia, response.item]); return ( - + { - console.log('submit'); - }} />