diff --git a/frontend-plataforma-tutoriais/src/pages/private/Nova pasta/createUser/index.tsx b/frontend-plataforma-tutoriais/src/pages/private/Nova pasta/createUser/index.tsx deleted file mode 100644 index 305d2ec..0000000 --- a/frontend-plataforma-tutoriais/src/pages/private/Nova pasta/createUser/index.tsx +++ /dev/null @@ -1,160 +0,0 @@ -import { useState } from "react"; -import { Link } from "react-router"; -import type { ApiErrorResponse, User } from "../../../types"; -import type { CreateUserResponse } from "../../../types"; -import styles from "./styles.module.css"; -import { LuArrowLeft } from "react-icons/lu"; -import { LuPlus } from "react-icons/lu"; - -export default function CreateUser() { - const [name, setName] = useState(""); - const [email, setEmail] = useState(""); - const [password, setPassword] = useState(""); - const [password_confirmation, setPasswordConfirmation] = useState(""); - const [role_id, setRoleId] = useState("2"); - const [createUserResponse, setCreateUserResponse] = useState(null); - const [error, setError] = useState(null); - - async function create() { - - //validação dos campos - - if (name.length < 3) { - setError({ - message: "Nome deve ter pelo menos 3 caracteres", - data: null, - errors: {} - }); - return; - } - - if (!email.includes('@')) { - setError({ - message: "Email inválido", - data: null, - errors: {} - }); - return; - } - - if (password !== password_confirmation) { - setError({ - message: "As senhas não coincidem", - data: null, - errors: {} - }); - return; - } - - if (password.length < 6) { - setError({ - message: "Password deve ter pelo menos 6 caracteres", - data: null, - errors: {} - }); - return; - } - - if (role_id === "") { - setError({ - message: "Cargo é obrigatório", - data: null, - errors: {} - }); - return; - } - - const payload = { - name: name, - email: email, - password: password, - password_confirmation: password_confirmation, - role_id: role_id, - } - - const response = await fetch("http://127.0.0.1:8000/api/users", { - method: "POST", - headers: { - Accept: "application/json", - "Content-Type": "application/json", - Authorization: `Bearer ${localStorage.getItem("token")}` - }, - body: JSON.stringify( - payload - ), - }); - - const data = await response.json(); - - if (response.ok){ - setCreateUserResponse({ - data: data.data as User, - message: data.message, - }); - setName(""); - setEmail(""); - setPassword(""); - setPasswordConfirmation(""); - setRoleId("2"); - } else { - setError({ - message: data.message, - data: null, - errors: data.errors - }); - } - } - - return ( -
-
- -
-

Criar Utilizador

- -
-
-
-
- - setName(e.target.value)} /> -
-
- - setEmail(e.target.value)} /> -
-
- - setPassword(e.target.value)} /> -
-
- - setPasswordConfirmation(e.target.value)} /> -
-
- - -
-
- - {createUserResponse?.message ? ( -
- {createUserResponse.message} -
- ) : error?.errors ? ( -
-

{error.message}

-
- ): null} - -
- -
-
-
-
- ) -} \ No newline at end of file diff --git a/frontend-plataforma-tutoriais/src/pages/private/Nova pasta/createUser/styles.module.css b/frontend-plataforma-tutoriais/src/pages/private/Nova pasta/createUser/styles.module.css deleted file mode 100644 index 95f234e..0000000 --- a/frontend-plataforma-tutoriais/src/pages/private/Nova pasta/createUser/styles.module.css +++ /dev/null @@ -1,47 +0,0 @@ -.container{ - width: 100%; - max-width: 1400px; - align-self: start; -} - -.title{ - color: var(--primary-contrast-color); - font-size: var(--size-font-title); -} - -.animateSpin{ - animation: spin 1s linear infinite; -} - -@keyframes spin{ - from{ - transform: rotate(0deg); - } - to{ - transform: rotate(360deg); - } -} - -.LinkIcon, .linkText{ - color: var(--text-black); -} - -.button:hover .LinkIcon, .button:hover .linkText{ - color: var(--primary-color); -} - -.createButton{ - background-color: var(--primary-color); - color: var(--text-white); - border: none; - border-radius: var(--border-radius-button); - padding: 10px 20px; - font-size: var(--size-font-small); - - font-weight: 500; - cursor: pointer; - transition: all 0.3s ease; - &:hover{ - background-color: var(--neutral-color); - } -} diff --git a/frontend-plataforma-tutoriais/src/pages/private/Nova pasta/createVideo/index.tsx b/frontend-plataforma-tutoriais/src/pages/private/Nova pasta/createVideo/index.tsx deleted file mode 100644 index aef9fb3..0000000 --- a/frontend-plataforma-tutoriais/src/pages/private/Nova pasta/createVideo/index.tsx +++ /dev/null @@ -1,280 +0,0 @@ -import { useEffect, useState } from "react"; -import { Link } from "react-router"; -import type { ApiErrorResponse, CreateCategoryResponse } from "../../../types"; -import type { CreateVideoResponse } from "../../../types"; -import type { Category } from "../../../types"; -import styles from "./styles.module.css"; -import { LuArrowLeft, LuPlus } from "react-icons/lu"; -import { LuUpload } from "react-icons/lu"; -import Swal from "sweetalert2"; - -export default function CreateVideo() { - const [title, setTitle] = useState(""); - const [description, setDescription] = useState(""); - const [videoFile, setVideoFile] = useState(null); - const [thumbnailFile, setThumbnailFile] = useState(null); - const [tags, setTags] = useState(""); - const [createVideoResponse, setCreateVideoResponse] = useState(null); - const [error, setError] = useState(null); - const [isUploading, setIsUploading] = useState(false); - const [uploadProgress, setUploadProgress] = useState(0); - const [category_ids, setCategoryIds] = useState([]); - - const [categories, setCategories] = useState([]); - const [createCategoryResponse, setCreateCategoryResponse] = useState(null); - - useEffect(() => { - getCategories(); - }, []); - - async function getCategories() { - const response = await fetch("http://127.0.0.1:8000/api/categories", { - method: "GET", - headers: { - Accept: "application/json", - "Content-Type": "application/json", - Authorization: `Bearer ${localStorage.getItem("token")}` - }, - }); - - const data = await response.json(); - - if (response.ok) { - setCategories(data.data); - setError(null); - } else { - setCategories([]); - setError(data as ApiErrorResponse); - } - } - - async function createVideo() { - setCreateVideoResponse(null); - setError(null); - - if (!videoFile || !thumbnailFile) { - setError({ - message: "Vídeo e thumbnail são obrigatórios.", - data: null, - errors: {}, - }); - return; - } - - const formData = new FormData(); - - formData.append("title", title); - formData.append("description", description); - formData.append("url", videoFile); - formData.append("thumbnail", thumbnailFile); - formData.append("tags", tags); - - category_ids.forEach(id => { - formData.append("category_ids[]", id); - }); - - setIsUploading(true); - setUploadProgress(0); - - const xhr = new XMLHttpRequest(); - - xhr.open("POST", "http://127.0.0.1:8000/api/create-video"); - xhr.setRequestHeader("Authorization", `Bearer ${localStorage.getItem("token")}`); - xhr.setRequestHeader("Accept", "application/json"); - xhr.upload.onprogress = (event) => { - if (event.lengthComputable) { - setUploadProgress(Math.round((event.loaded / event.total) * 100)); - } - }; - - xhr.onload = () => { - setIsUploading(false); - - let data: any = null; - - try { - data = xhr.responseText ? JSON.parse(xhr.responseText) : null; - } catch { - setError({ message: "Resposta inválida do servidor.", data: null, errors: {} }); - return; - } - - if (xhr.status >= 200 && xhr.status < 300) { - setCreateVideoResponse({ message: "Vídeo criado com sucesso.", data: data.data }); - setError(null); - setUploadProgress(100); - setIsUploading(false); - setTitle(""); - setDescription(""); - setVideoFile(null); - setThumbnailFile(null); - setTags(""); - setCategoryIds([]); - } else { - setCreateVideoResponse(null); - setIsUploading(false); - setError( - data ?? { message: `Erro ${xhr.status} no upload.`, data: null, errors: {} } - ); - } - }; - - xhr.onerror = () => { - setIsUploading(false); - setError({ message: "Falha de rede durante upload.", data: null, errors: {} }); - }; - - xhr.send(formData); - } - - function handleCreateCategory() { - Swal.fire({ - title: 'Criar nova categoria', - input: 'text', - inputPlaceholder: 'Categoria...', - showCancelButton: true, - confirmButtonText: 'Adicionar', - cancelButtonText: 'Cancelar', - confirmButtonColor: 'var(--primary-color)', - inputValidator: (value) => { - if (!value) { - return 'Indique o nome da categoria!'; - } - } - }).then((result) => { - if (result.isConfirmed) { - const categoryName = result.value; - createCategory(categoryName); - } - }); - } - - async function createCategory(categoryName: string ) { - const response = await fetch("http://127.0.0.1:8000/api/categories", { - method: "POST", - headers: { - Accept: "application/json", - "Content-Type": "application/json", - Authorization: `Bearer ${localStorage.getItem("token")}` - }, - body: JSON.stringify({ - name: categoryName - }) - }); - - const data = await response.json(); - setCreateCategoryResponse(data); - setError(data as ApiErrorResponse); - - if (response.ok) { - setCreateCategoryResponse(data); - getCategories(); - setError(null); - } else { - setCreateCategoryResponse(null); - setError(data as ApiErrorResponse); - } - } - - const handleCheckbox = (e: React.ChangeEvent) => { - const { value, checked } = e.target; - setCategoryIds(prev => - checked ? [...prev, value] : prev.filter(id => id !== value) - ); - }; - - return ( -
-
- -
-

Adicionar Vídeo

-
-
- - setTitle(e.target.value)} required/> -
-
- -