Skip to content

Commit

Permalink
fix share modal when restricted
Browse files Browse the repository at this point in the history
  • Loading branch information
FSM1 committed Sep 23, 2021
1 parent a7ab567 commit 65a5be8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const CSFFileBrowser: React.FC<IFileBrowserModuleProps> = () => {
if (accountInArrears) {
addToast({
type:'error',
title: 'Unable to upload',
title: 'Uploads disabled',
subtitle: 'Oops! You need to pay for this month to upload more content.'
})
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useFileBrowser } from "../../../Contexts/FileBrowserContext"
import clsx from "clsx"
import { useEffect } from "react"
import { nameValidator } from "../../../Utils/validationSchema"
import { useFilesApi } from "../../../Contexts/FilesApiContext"

const useStyles = makeStyles(
({ breakpoints, constants, palette, typography, zIndex }: CSFTheme) => {
Expand Down Expand Up @@ -188,6 +189,7 @@ interface IShareFileProps {
const ShareModal = ({ close, file, filePath }: IShareFileProps) => {
const classes = useStyles()
const { handleCreateSharedFolder } = useCreateOrEditSharedFolder()
const { accountInArrears } = useFilesApi()
const [sharedFolderName, setSharedFolderName] = useState("")
const { sharedFolderReaders, sharedFolderWriters, handleLookupUser, onNewUsers, usersError } = useLookupSharedFolderUser()
const [isUsingCurrentBucket, setIsUsingCurrentBucket] = useState(true)
Expand All @@ -213,23 +215,25 @@ const ShareModal = ({ close, file, filePath }: IShareFileProps) => {
.filter(buck => buck.type === "share" || buck.type === "csf")
// filter out the current bucket
.filter(buck => buck.id !== bucket?.id)
// all buckets where the user is reader or writer
// all buckets where the user is owner or writer
.filter(buck => !!buck.writers.find((w) => w.uuid === profile.userId) || !!buck.owners.find((o) => o.uuid === profile.userId))
// filter out CSF and share buckets where user is an owner if their account is restricted
.filter(buck => !(!!accountInArrears && (buck.type === 'csf' || !!buck.owners.find(o => o.uuid === profile.userId))))
.map(buck => ({
label: buck.name || t`Home`,
value: buck.id
}))
}
, [bucket, buckets, profile])
, [bucket, buckets, profile, accountInArrears])

const hasNoSharedBucket = useMemo(() => bucketsOptions.length === 0, [bucketsOptions.length])

// if the user has no shared bucket, we default to new folder creation
useEffect(() => {
if (hasNoSharedBucket) {
if (hasNoSharedBucket && !accountInArrears) {
setIsUsingCurrentBucket(false)
}
}, [hasNoSharedBucket])
}, [hasNoSharedBucket, accountInArrears])

const onNameChange = useCallback((value?: string | number) => {
if (value === undefined) return
Expand Down

0 comments on commit 65a5be8

Please sign in to comment.