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