Skip to content

Commit

Permalink
Merge pull request #25 from ifspcbt-devspace/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
oproprioleonardo authored Oct 6, 2024
2 parents 6b72d43 + 9feaedb commit 7278ad9
Show file tree
Hide file tree
Showing 20 changed files with 147 additions and 110 deletions.
45 changes: 0 additions & 45 deletions public/images/default-event-thumb.svg

This file was deleted.

Binary file added public/images/default_thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/images/festa.webp
Binary file not shown.
Binary file removed public/images/festajunina.jpg
Binary file not shown.
Binary file removed public/images/hallowif.png
Binary file not shown.
Binary file removed public/images/homemfesta.png
Binary file not shown.
Binary file removed public/images/iconehalloween.jpg
Binary file not shown.
Binary file removed public/images/iconeinterrogacao.webp
Binary file not shown.
Binary file removed public/images/ponto.webp
Binary file not shown.
2 changes: 1 addition & 1 deletion src/app/auth/log-in/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function Login() {
if (respLogin && respLogin.error) {
setError(respLogin.error);
} else {
toast.success("Conta criada com sucesso, redirecionando...", toastConfig);
toast.success("Login realizado com sucesso, redirecionando...", toastConfig);
setTimeout(() => router.push(redirectTo), 1500)
}
setIsLoading(false)
Expand Down
26 changes: 13 additions & 13 deletions src/app/auth/sign-up/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {generateRandomUsername} from "@/utils";
import {toast} from "react-toastify";
import {isAuthenticated, login, register} from "@/server-actions/auth.action";
import ConfirmRegister from "@/components/register/ConfirmRegister";
import {isCPF, isEmail, isNumberPhone, isValidBirthDate} from "@/validations";
import {isEmail, isNumberPhone, isRG, isValidBirthDate} from "@/validations";
import {toastConfig} from "@/constants";

export default function RegisterPage() {
Expand All @@ -26,7 +26,7 @@ export default function RegisterPage() {

function Register() {
const [name, setName] = useState("");
const [cpf, setCpf] = useState("");
const [document, setDocument] = useState("");
const [phone, setPhone] = useState("");
const [birthDate, setBirthDate] = useState("");
const [email, setEmail] = useState("");
Expand Down Expand Up @@ -55,8 +55,8 @@ function Register() {
mask: "(__) _____-____",
replacement: {_: /\d/},
});
const cpfRef = useMask({
mask: "nnn.nnn.nnn-nn",
const documentRef = useMask({
mask: "nn.nnn.nnn-n",
replacement: {n: /\d/},
});

Expand All @@ -73,10 +73,10 @@ function Register() {
if (email === "") return false;
return !isEmail(email.trim());
}, [email]);
const isCPFInvalid = useMemo(() => {
if (cpf === "") return false;
return !isCPF(cpf);
}, [cpf])
const isDocumentInvalid = useMemo(() => {
if (document === "") return false;
return !isRG(document);
}, [document])
const isPhoneInvalid = useMemo(() => {
if (phone === "") return false;
return !isNumberPhone(phone);
Expand Down Expand Up @@ -107,7 +107,7 @@ function Register() {
formData.append("username", generateRandomUsername());
formData.append("password", password);
formData.append("birth_date", formatDate(birthDate));
formData.append("cpf", cpf);
formData.append("document", document);
formData.append("phone_number", phone);

const resp = await register(formData);
Expand All @@ -127,12 +127,12 @@ function Register() {

const handleOpenModal = (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (email === "" || password === "" || confirmPassword === "" || name === "" || birthDate === "" || cpf === "" || phone === "") {
if (email === "" || password === "" || confirmPassword === "" || name === "" || birthDate === "" || document === "" || phone === "") {
toast.error("Preencha todos os campos", toastConfig)
setIsLoading(false);
return;
}
if (isEmailInvalid || isPasswordInvalid || isConfirmPasswordInvalid || isNameInvalid || isBirthDateInvalid || isCPFInvalid || isPhoneInvalid) {
if (isEmailInvalid || isPasswordInvalid || isConfirmPasswordInvalid || isNameInvalid || isBirthDateInvalid || isDocumentInvalid || isPhoneInvalid) {
toast.error("Corrija as credenciais primeiro", toastConfig);
setIsLoading(false);
return;
Expand Down Expand Up @@ -169,8 +169,8 @@ function Register() {
classNames={{inputWrapper: "rounded-[9px]", base: "mb-1"}} type="text" autoComplete="off"
isRequired={true}/>

<Input placeholder="CPF" name="cpf" title="CPF" ref={cpfRef}
isInvalid={isCPFInvalid} errorMessage="O CPF é inválido" onValueChange={setCpf}
<Input placeholder="RG" name="document" title="R.G." ref={documentRef}
isInvalid={isDocumentInvalid} errorMessage="O RG é inválido" onValueChange={setDocument}
classNames={{inputWrapper: "rounded-[9px]", base: "mb-1"}} type="text" autoComplete="off"
isRequired={true}/>

Expand Down
45 changes: 35 additions & 10 deletions src/app/user/account/page.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
"use client";

import Header from "@/components/Header";
import React, {useEffect, useMemo, useState} from "react";
import React, {FormEvent, useEffect, useMemo, useState} from "react";
import Footer from "@/components/Footer";
import {Button, Input} from "@nextui-org/react";
import {useMask} from "@react-input/mask";
import {isRG} from "@/validations";
import {getSession} from "@/server-actions/auth.action";
import {usePathname, useRouter} from "next/navigation";
import {toastConfig} from "@/constants";
import {toast} from "react-toastify";
import {updateUser} from "@/server-actions/user.action";

export default function UserAccount() {
const [rg, setRg] = useState("");
const router = useRouter();
const pathname = usePathname();
const [session, setSession] = useState<any>();
const [hasDocument, setHasDocument] = useState(false);
const [isLoading, setIsLoading] = useState(false);

useEffect(() => {
Promise.all([getSession()]).then(([session]) => {
setSession(session);
if (!session) router.push(`/auth/log-in?redir=${pathname}`);
else if (session.user.document_initials === undefined || session.user.document_initials === null || session.user.document_initials === "") {
toast.error("Complete seu cadastro.", toastConfig);
setHasDocument(false);
} else {
setHasDocument(true);
setRg(session.user.document_initials)
}
});
}, [setSession]);

Expand All @@ -28,9 +40,22 @@ export default function UserAccount() {
});

const isRGInvalid = useMemo(() => {
if (rg === "") return false;
if (rg === "" || rg === undefined || rg === null) return true;
if (rg === session?.user.document_initials) return false;
return !isRG(rg);
}, [rg])
}, [rg, session?.user.document_initials])

const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {
e.preventDefault()
setIsLoading(true);
const resp = await updateUser(rg);
if ("error" in resp) {
toast.error(resp.error, toastConfig);
}
toast.success("Dados alterados com sucesso.")
setHasDocument(true)
setIsLoading(false);
}

if (!session) return <><title>Perfil | IFSP Eventos</title></>;

Expand All @@ -42,7 +67,7 @@ export default function UserAccount() {
<span className={`text-2xl font-semibold`}>Detalhes da conta</span>
<hr className={`my-4 w-full`}/>

<form className="block mt-0">
<form className="block mt-0" onSubmit={handleSubmit}>

<span className={`font-medium mb-1 mt-4 block`}>E-mail</span>
<Input maxLength={128} name="email" title="E-mail"
Expand All @@ -60,20 +85,20 @@ export default function UserAccount() {

<span className={`font-medium mb-1 mt-4 block`}>R.G.</span>
<Input maxLength={16} name="rg" title="RG"
ref={rgRef}
ref={hasDocument ? undefined : rgRef}
disabled={hasDocument}
isInvalid={isRGInvalid}
onValueChange={setRg}
value={rg}
errorMessage="O RG informado é inválido"
classNames={{inputWrapper: "rounded-[9px] border-1", base: "mb-1"}} type="text"
autoComplete="off"
isRequired={true}/>

<Button isLoading={false} type="submit"
onSubmit={(e) => {
e.preventDefault()
}}
<Button isLoading={isLoading} type="submit"
isDisabled={isRGInvalid || hasDocument}
className="mt-4 inline-block cursor-pointer duration-200 bg-neutral-900 hover:bg-opacity-90 text-white px-4 py-1.5 h-fit w-fit rounded-lg">
{"Salvar alterações"}
{isLoading ? "" : "Salvar alterações"}
</Button>

</form>
Expand Down
2 changes: 1 addition & 1 deletion src/components/events/EventCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function ({
<Image
src={imgUrl}
onError={() => {
setImgUrl("/images/default-event-thumb.svg");
setImgUrl("/images/default-thumb.png");
}}
alt="event-image"
quality={100}
Expand Down
21 changes: 13 additions & 8 deletions src/components/events/single/EventView.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import React, {Dispatch, SetStateAction, Suspense, useEffect, useState} from "react";
import {Event} from "@/models";
import {Event, SessionData} from "@/models";
import {usePathname, useRouter, useSearchParams} from "next/navigation";
import {getEvent} from "@/server-actions/event.action";
import {toast} from "react-toastify";
Expand All @@ -11,7 +11,7 @@ import Link from "next/link";
import {useDisclosure} from "@nextui-org/react";
import ConfirmSubscription from "@/components/events/subscription/ConfirmSubscription";
import {enrollUser} from "@/server-actions/enrollment.action";
import {isAuthenticated} from "@/server-actions/auth.action";
import {getSession} from "@/server-actions/auth.action";
import "./eventview.css"

export default function EventViewComponent({params}: { params: { id: string } }) {
Expand All @@ -26,8 +26,8 @@ export function EventView({params}: { params: { id: string } }) {
const searchParams = useSearchParams();
const [event, setEvent] = useState<Event>();
const {isOpen, onOpen, onOpenChange} = useDisclosure();
const [imgUrl, setImgUrl] = useState("/images/default-event-thumb.svg");
const [isAuth, setIsAuth] = useState(false);
const [imgUrl, setImgUrl] = useState("/images/default-thumb.png");
const [session, setSession] = useState<SessionData>();
const pathname = usePathname();
const router = useRouter();

Expand All @@ -41,8 +41,8 @@ export function EventView({params}: { params: { id: string } }) {
}
setEvent(event);
setImgUrl(`https://eventos.ifspcbt.shop/api/v1/event/${event.id}/thumbnail`);
const isAut = await isAuthenticated();
setIsAuth(isAut);
const sessionData = await getSession();
if (sessionData) setSession(sessionData);
if (searchParams.get("open")) onOpen();
}
load();
Expand All @@ -55,10 +55,15 @@ export function EventView({params}: { params: { id: string } }) {

const handleAction = async (open: () => void, setTicketID: Dispatch<SetStateAction<string>>) => {
if (event) {
if (!isAuth) {
if (!session) {
router.push(`/auth/log-in?redir=${pathname + `?open=true`}`);
return;
}
if (!session.user.document_initials) {
router.push(`/user/account`);
return;
}

const resp = await enrollUser(event?.id);
if (typeof resp === "object") {
toast.error(resp.error, toastConfig);
Expand All @@ -81,7 +86,7 @@ export function EventView({params}: { params: { id: string } }) {

<DarkPageHeader title={`${event?.name}`}
imgUrl={imgUrl}
onError={() => setImgUrl("/images/default-event-thumb.svg")}
onError={() => setImgUrl("/images/default-thumb.png")}
subtitle={`Por IFSP Cubatão - ${event?.init_date.toLocaleString([], {dateStyle: "short"})}`}/>
<div className="py-10 grid grid-cols-10 w-full px-4 xl:px-0">
<div className={"col-start-1 col-span-10 xl:col-start-3 xl:col-span-6"}>
Expand Down
5 changes: 3 additions & 2 deletions src/constants/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import {Bounce, ToastOptions} from "react-toastify";

export const toastConfig: ToastOptions = {
position: "top-right",
autoClose: 5000,
autoClose: 3000,
hideProgressBar: true,
closeOnClick: false,
pauseOnHover: true,
pauseOnHover: false,
draggable: true,
progress: undefined,
pauseOnFocusLoss: false,
theme: "light",
transition: Bounce,
};
2 changes: 1 addition & 1 deletion src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface User {
username: string;
role: Role;
birth_date: string;
cpf_initials: string;
document_initials: string;
phone_number_initials: string;
company_id: string;
}
Expand Down
4 changes: 2 additions & 2 deletions src/server-actions/auth.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ export async function register(data: FormData) {
const password = data.get("password") as string;
const birth_date = data.get("birth_date") as string;
if (birth_date === "") return {error: "Data de nascimento inválida"};
const cpf = data.get("cpf") as string;
const document = data.get("document") as string;
const phone_number = data.get("phone_number") as string;
return await authService.register({
name,
email,
username,
password,
birth_date,
cpf,
document,
phone_number,
});
}
Expand Down
9 changes: 8 additions & 1 deletion src/server-actions/user.action.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
"use server";

import { UserService } from "@/services/users.service";
import {UserService} from "@/services/users.service";

export async function getUser(id: string) {
const userService = new UserService();
return await userService.getUser(id);
}

export async function updateUser(document: string) {
const userService = new UserService();
return await userService.updateUser({
document
});
}
Loading

0 comments on commit 7278ad9

Please sign in to comment.