-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c35e1c
commit 930f67c
Showing
34 changed files
with
874 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright 2023 Arkemis S.r.l. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
export const acceptedRoles = ["super_admin"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/** | ||
* Copyright 2023 Arkemis S.r.l. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import React, { useState } from "react"; | ||
import { useDropzone } from "react-dropzone"; | ||
import { ArrowUpTrayIcon, XMarkIcon } from "@heroicons/react/24/outline"; | ||
import toast from "react-hot-toast"; | ||
import { formatBytes } from "@/utils/file"; | ||
interface DropzoneProps { | ||
value?: string; | ||
label?: string; | ||
onChange?(files: File[]): void; | ||
} | ||
|
||
interface AcceptedFile extends File { | ||
path?: string; | ||
} | ||
|
||
const maxSize = 5243000; // 5Mb as bytes | ||
export default function Dropzone(props: DropzoneProps) { | ||
const { value, label, onChange } = props; | ||
const [selectedFiles, setSelectedFiles] = useState<File[]>([]); | ||
const { acceptedFiles, getRootProps, getInputProps } = useDropzone({ | ||
multiple: false, | ||
maxSize, | ||
onDrop: (acceptedFiles, fileRejections) => { | ||
setSelectedFiles([...selectedFiles, ...acceptedFiles]); | ||
onChange?.([...selectedFiles, ...acceptedFiles]); | ||
fileRejections.forEach((file) => { | ||
file.errors.forEach((err) => { | ||
if (err.code === "file-too-large") { | ||
toast.error(`${err.message}`); | ||
} | ||
|
||
if (err.code === "file-invalid-type") { | ||
toast.error(`${err.message}`); | ||
} | ||
}); | ||
}); | ||
}, | ||
}); | ||
|
||
const removeFile = (file: File) => { | ||
const newFiles = [...selectedFiles]; | ||
newFiles.splice(newFiles.indexOf(file), 1); | ||
setSelectedFiles(newFiles); | ||
onChange?.(newFiles); | ||
}; | ||
|
||
const removeAll = () => { | ||
setSelectedFiles([]); | ||
onChange?.([]); | ||
}; | ||
|
||
const File = (file: { path?: string; size: number }) => ( | ||
<li className="flex gap-2 text-xs" key={file.path}> | ||
<XMarkIcon | ||
className="w-4 cursor-pointer text-error" | ||
onClick={() => removeFile(file as File)} | ||
/> | ||
{file.path} - {formatBytes(file.size)} | ||
</li> | ||
); | ||
|
||
return ( | ||
<> | ||
{label} | ||
{selectedFiles.length === 0 && !value && ( | ||
<section> | ||
<div | ||
{...getRootProps({ className: "dropzone" })} | ||
className="min-h-20 flex cursor-pointer flex-col items-center justify-center | ||
gap-1 rounded-xl border-2 border-dashed border-[rgba(255,255,255,0.2)] p-12 text-center duration-75 | ||
hover:border-primary" | ||
> | ||
<input {...getInputProps()} /> | ||
<ArrowUpTrayIcon className="h-5 w-5" /> | ||
<p className="font-semibold">Upload file</p> | ||
<p className="text-xs">{formatBytes(maxSize)} max. file size</p> | ||
</div> | ||
</section> | ||
)} | ||
<aside className="grid gap-2"> | ||
{selectedFiles.length > 0 ? ( | ||
<ul> | ||
{acceptedFiles.map((file: AcceptedFile, index) => ( | ||
<File key={index} path={file.path} size={file.size} /> | ||
))} | ||
</ul> | ||
) : ( | ||
value && ( | ||
<ul> | ||
{/*// TODO: check value of backend with load_images */} | ||
{/*// @ts-ignore */} | ||
<File path={value.path} size={1000000} /> | ||
</ul> | ||
) | ||
)} | ||
</aside> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright 2023 Arkemis S.r.l. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export function ExpandIcon({ className }: { className?: string }) { | ||
return ( | ||
<svg | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
className={className} | ||
> | ||
<path | ||
d="M19 9L12.7071 15.2929C12.3166 15.6834 11.6834 15.6834 11.2929 15.2929L5 9" | ||
stroke="#fff" | ||
strokeWidth="1.5" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
/> | ||
</svg> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright 2023 Arkemis S.r.l. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import useClient from "@/arke/useClient"; | ||
import { Input } from "@arkejs/ui"; | ||
import { useRef, useState } from "react"; | ||
import useOnClickOutside from "@/hooks/useOnClickOutside"; | ||
|
||
interface PermissionInputProps { | ||
role: string; | ||
value: string; | ||
} | ||
export function PermissionInput(props: PermissionInputProps) { | ||
const client = useClient(); | ||
const [value, setValue] = useState(props.value); | ||
const inputRef = useRef<HTMLDivElement>(null); | ||
|
||
function onUpdateData() { | ||
console.log(value); | ||
} | ||
|
||
useOnClickOutside(inputRef, onUpdateData); | ||
return ( | ||
<Input | ||
{...props} | ||
label="" | ||
// @ts-ignore | ||
itemRef={inputRef} | ||
value={value} | ||
onChange={(e) => setValue(e.target.value)} | ||
onKeyDown={(e) => e.key === "Enter" && onUpdateData()} | ||
onBlur={onUpdateData} | ||
/> | ||
); | ||
} |
Oops, something went wrong.