final touch
This commit is contained in:
parent
41df9d0c82
commit
88d73703f8
|
@ -4,6 +4,7 @@ import { useEffect, useState } from "react";
|
|||
import { styles } from "./styles";
|
||||
import { Options } from "./types";
|
||||
import CreatableSelect from "react-select/creatable";
|
||||
import Select from "react-select";
|
||||
|
||||
type Props = {
|
||||
onChange: any;
|
||||
|
@ -14,12 +15,14 @@ type Props = {
|
|||
value?: number;
|
||||
}
|
||||
| undefined;
|
||||
creatable?: boolean;
|
||||
};
|
||||
|
||||
export default function CollectionSelection({
|
||||
onChange,
|
||||
defaultValue,
|
||||
showDefaultValue = true,
|
||||
creatable = true,
|
||||
}: Props) {
|
||||
const { collections } = useCollectionStore();
|
||||
const router = useRouter();
|
||||
|
@ -47,16 +50,31 @@ export default function CollectionSelection({
|
|||
setOptions(formatedCollections);
|
||||
}, [collections]);
|
||||
|
||||
return (
|
||||
<CreatableSelect
|
||||
isClearable={false}
|
||||
className="react-select-container"
|
||||
classNamePrefix="react-select"
|
||||
onChange={onChange}
|
||||
options={options}
|
||||
styles={styles}
|
||||
defaultValue={showDefaultValue ? defaultValue : null}
|
||||
// menuPosition="fixed"
|
||||
/>
|
||||
);
|
||||
if (creatable) {
|
||||
return (
|
||||
<CreatableSelect
|
||||
isClearable={false}
|
||||
className="react-select-container"
|
||||
classNamePrefix="react-select"
|
||||
onChange={onChange}
|
||||
options={options}
|
||||
styles={styles}
|
||||
defaultValue={showDefaultValue ? defaultValue : null}
|
||||
// menuPosition="fixed"
|
||||
/>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<Select
|
||||
isClearable={false}
|
||||
className="react-select-container"
|
||||
classNamePrefix="react-select"
|
||||
onChange={onChange}
|
||||
options={options}
|
||||
styles={styles}
|
||||
defaultValue={showDefaultValue ? defaultValue : null}
|
||||
// menuPosition="fixed"
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ export default function BulkEditLinksModal({ onClose }: Props) {
|
|||
|
||||
const setCollection = (e: any) => {
|
||||
const collectionId = e?.value || null;
|
||||
console.log(updatedValues);
|
||||
setUpdatedValues((prevValues) => ({ ...prevValues, collectionId }));
|
||||
};
|
||||
|
||||
|
@ -66,6 +67,7 @@ export default function BulkEditLinksModal({ onClose }: Props) {
|
|||
<CollectionSelection
|
||||
showDefaultValue={false}
|
||||
onChange={setCollection}
|
||||
creatable={false}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
@ -74,7 +76,7 @@ export default function BulkEditLinksModal({ onClose }: Props) {
|
|||
<TagSelection onChange={setTags} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="ml-auto w-1/2 p-3">
|
||||
<div className="sm:ml-auto w-1/2 p-3">
|
||||
<label className="flex items-center gap-2 ">
|
||||
<input
|
||||
type="checkbox"
|
||||
|
|
|
@ -124,6 +124,7 @@ export default function EditLinkModal({ onClose, activeLink }: Props) {
|
|||
label: "Unorganized",
|
||||
}
|
||||
}
|
||||
creatable={false}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
|
|
|
@ -16,6 +16,10 @@ export default async function updateLinkById(
|
|||
};
|
||||
|
||||
const collectionIsAccessible = await getPermission({ userId, linkId });
|
||||
const targetCollectionIsAccessible = await getPermission({
|
||||
userId,
|
||||
collectionId: data.collection.id,
|
||||
});
|
||||
|
||||
const memberHasAccess = collectionIsAccessible?.members.some(
|
||||
(e: UsersAndCollections) => e.userId === userId && e.canUpdate
|
||||
|
@ -25,6 +29,28 @@ export default async function updateLinkById(
|
|||
collectionIsAccessible?.ownerId === data.collection.ownerId &&
|
||||
data.collection.ownerId === userId;
|
||||
|
||||
const targetCollectionsAccessible =
|
||||
targetCollectionIsAccessible?.ownerId === userId;
|
||||
|
||||
const targetCollectionMatchesData = data.collection.id
|
||||
? data.collection.id === targetCollectionIsAccessible?.id
|
||||
: true && data.collection.name
|
||||
? data.collection.name === targetCollectionIsAccessible?.name
|
||||
: true && data.collection.ownerId
|
||||
? data.collection.ownerId === targetCollectionIsAccessible?.ownerId
|
||||
: true;
|
||||
|
||||
if (!targetCollectionsAccessible)
|
||||
return {
|
||||
response: "Target collection is not accessible.",
|
||||
status: 401,
|
||||
};
|
||||
else if (!targetCollectionMatchesData)
|
||||
return {
|
||||
response: "Target collection does not match the data.",
|
||||
status: 401,
|
||||
};
|
||||
|
||||
const unauthorizedSwitchCollection =
|
||||
!isCollectionOwner && collectionIsAccessible?.id !== data.collection.id;
|
||||
|
||||
|
|
|
@ -3,12 +3,14 @@ import { prisma } from "@/lib/api/db";
|
|||
type Props = {
|
||||
userId: number;
|
||||
collectionId?: number;
|
||||
collectionName?: string;
|
||||
linkId?: number;
|
||||
};
|
||||
|
||||
export default async function getPermission({
|
||||
userId,
|
||||
collectionId,
|
||||
collectionName,
|
||||
linkId,
|
||||
}: Props) {
|
||||
if (linkId) {
|
||||
|
@ -24,10 +26,11 @@ export default async function getPermission({
|
|||
});
|
||||
|
||||
return check;
|
||||
} else if (collectionId) {
|
||||
} else if (collectionId || collectionName) {
|
||||
const check = await prisma.collection.findFirst({
|
||||
where: {
|
||||
id: collectionId,
|
||||
id: collectionId || undefined,
|
||||
name: collectionName || undefined,
|
||||
OR: [{ ownerId: userId }, { members: { some: { userId } } }],
|
||||
},
|
||||
include: { members: true },
|
||||
|
|
|
@ -152,6 +152,11 @@ const useLinkStore = create<LinkStore>()((set) => ({
|
|||
links.some((link) => link.id === e.id)
|
||||
? {
|
||||
...e,
|
||||
collectionId: newData.collectionId ?? e.collectionId,
|
||||
collection: {
|
||||
...e.collection,
|
||||
id: newData.collectionId ?? e.collection.id,
|
||||
},
|
||||
tags: removePreviousTags
|
||||
? [...(newData.tags ?? [])]
|
||||
: [...e.tags, ...(newData.tags ?? [])],
|
||||
|
|
Ŝarĝante…
Reference in New Issue