Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Component Modal #291

Merged
merged 22 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
96f31c3
feat: create component modal root
Ar3secchim Jul 21, 2023
ce58afa
fix: update dropzone with ModalContext
Ar3secchim Jul 21, 2023
179fccd
fix: update organize folder componentes modal
Ar3secchim Jul 21, 2023
ff84a39
refactor: separation of ModalContentAlert component from ModalContent
Ar3secchim Jul 21, 2023
4429c1b
feat: update ModalAlert
Ar3secchim Jul 21, 2023
f785700
fix: updating imports in the components that use the modal
Ar3secchim Jul 22, 2023
c2f0e6b
feat: update style modalAlert
Ar3secchim Jul 22, 2023
c118fe2
feat: context edit profile modal
salviotonon Jul 6, 2023
fb1b1c7
feat: add skeleton card profile
salviotonon Jul 6, 2023
595ae4d
feat: change Dropzone component to use modal hook
oliveirabalsa Jul 6, 2023
c332de6
refactor(header): change text name
oliveirabalsa Jul 18, 2023
d85605b
fix(image): change image schema
oliveirabalsa Jul 18, 2023
1bf0c72
fix(mentorFormatData): change from object to string
oliveirabalsa Jul 18, 2023
ad8010e
fix(image): image types
oliveirabalsa Jul 18, 2023
e202ea0
feat: create component modal root
Ar3secchim Jul 21, 2023
2cb13d9
fix: update dropzone with ModalContext
Ar3secchim Jul 21, 2023
50e41a3
fix: solution of conflicts generated by rebase
Ar3secchim Jul 23, 2023
539fcdf
fix: solution of conflicts generated by rebase
Ar3secchim Jul 23, 2023
82e8a4b
Merge branch 'dev' into refactor/componentModal
Ar3secchim Jul 23, 2023
8c7d2b7
fix: duplication solution accused in sonar lint and lint build
Ar3secchim Jul 23, 2023
85d99e0
fix: solution lint build
Ar3secchim Jul 23, 2023
c7f45f9
fix: solution build storybook
Ar3secchim Jul 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@apollo/client": "^3.7.12",
"@radix-ui/colors": "^0.1.8",
"@radix-ui/react-accordion": "^1.1.1",
"@radix-ui/react-alert-dialog": "^1.0.4",
"@radix-ui/react-checkbox": "^1.0.3",
"@radix-ui/react-dialog": "^1.0.3",
"@radix-ui/react-icons": "^1.3.0",
Expand Down
10 changes: 7 additions & 3 deletions src/components/Dropzone/Dropzone.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useMutation } from "@apollo/client";
import Spinner from "@components/Spinner";
import { useUser } from "@hooks/useUser";
import { useModal } from "contexts/ModalContext";
import { ModalActionTypes } from "contexts/types";
import { useTheme } from "next-themes";
import { Dispatch, SetStateAction } from "react";
import { useDropzone } from "react-dropzone";
Expand All @@ -13,15 +15,17 @@ interface IDropzone {
setIsModalOpen: Dispatch<SetStateAction<boolean>>;
}

const Dropzone = ({ setIsModalOpen }: IDropzone) => {
const Dropzone = () => {
const [uploadImage, { loading }] = useMutation(UPDATE_USER_PHOTO, {
refetchQueries: [GET_ME],
});
const { user, setUser } = useUser();
const { theme } = useTheme();

const { openModal, closeModal } = useModal();

const onDrop = async (acceptedFiles: File[]) => {
setIsModalOpen(false);
closeModal(ModalActionTypes.SETTINGS_MODAL);
const [selectedFile] = acceptedFiles;
Swal.fire({
customClass: {
Expand All @@ -37,7 +41,7 @@ const Dropzone = ({ setIsModalOpen }: IDropzone) => {
confirmButtonText: "Sim, mudar",
cancelButtonText: "Cancelar",
}).then(async (result) => {
setIsModalOpen(true);
openModal(ModalActionTypes.SETTINGS_MODAL);
if (result.isConfirmed) {
try {
await uploadImage({
Expand Down
249 changes: 126 additions & 123 deletions src/components/EditProfile/EditProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
import { useMutation } from "@apollo/client";
import Button from "@components/Button/Button";
import Input from "@components/Input";
import Modal from "@components/Modal";

import {
IEditProfileSubmitData,
editProfileFormSchema,
} from "@components/EditProfile/EditProfile.form";
import SelectLocation from "@components/LocationSelector/SelectLocation";
import { Modal } from "@components/Modal/Modal";
import SelectSkillsInput from "@components/MultiSelect/SelectSkillsInput";
import Textarea from "@components/Textarea/Textarea";
import { useFetch } from "@hooks/useFetch";
import { Country, State } from "@hooks/useFetch.types";
import { useTypedQuery } from "@hooks/useTypedQuery";
import { useUser } from "@hooks/useUser";
import { Dispatch, SetStateAction, useEffect, useState } from "react";
import { SubmitHandler, useForm } from "react-hook-form";
import { toast } from "react-toastify";
import { USER_UPDATE_DATA } from "services/apollo/mutations";
import { GET_ME, GET_MENTORS } from "services/apollo/queries";
import { queriesIndex as api } from "services/apollo/queries/queries.index";
import { z } from "zod";
import {
EditProfileProps,
IEditProfileFormData,
ILocationInterface,
} from "./EditProfile.types";
import SelectLocation from "@components/LocationSelector/SelectLocation";
import { Country, State } from "@hooks/useFetch.types";
import { useFetch } from "@hooks/useFetch";
import { GET_ME, GET_MENTORS } from "services/apollo/queries";
import { SubmitHandler, useForm } from "react-hook-form";
import SelectSkillsInput from "@components/MultiSelect/SelectSkillsInput";
import { queriesIndex as api } from "services/apollo/queries/queries.index";
import {
IEditProfileSubmitData,
editProfileFormSchema,
} from "@components/EditProfile/EditProfile.form";
import { z } from "zod";
import { useTypedQuery } from "@hooks/useTypedQuery";

const EditProfile = ({
openEditProfile,
Expand Down Expand Up @@ -128,117 +129,119 @@ const EditProfile = ({
};

return (
<Modal open={openEditProfile} onOpenChange={setOpenEditProfile}>
<div className="max-xl:px-5 py-16 w-[300px] xs:w-[380px] sm:w-[600px] md:w-auto p-2 lg:px-20">
<form
className="max-md:w-auto md:w-[672px] text-start"
onSubmit={handleSubmit(submitHandler)}
>
<div className="flex flex-col md:flex-row gap-2 w-full">
<Input
type="text"
{...register("firstName")}
label="Nome"
pattern="^[A-Za-zÀ-ÿ ,.'-]+$"
defaultValue={userCurrent.firstName}
/>
<Input
type="text"
{...register("lastName")}
label="Sobrenome"
pattern="^[A-Za-zÀ-ÿ ,.'-]+$"
defaultValue={userCurrent.lastName ?? ""}
/>
</div>
<div className="flex flex-col gap-2">
<Input
type="text"
{...register("jobTitle")}
label="Profissão"
pattern="^[A-Za-zÀ-ÿ ,.'-]+$"
defaultValue={userCurrent.jobTitle ?? ""}
/>
<Textarea
{...register("biography")}
label="Bio"
defaultValue={userCurrent.biography ?? ""}
/>
<Textarea
{...register("description")}
label="Experiência"
defaultValue={userCurrent.description ?? ""}
/>
<SelectLocation
onSelect={handleLocationChange(setSelectedCountry)}
name="country"
label="Pais"
requiredField={true}
options={countries}
placeholder="Selecione um Pais"
value={
selectedCountry || {
label: userCurrent.country,
value: userCurrent.country,
<Modal.Root open={openEditProfile} onOpenChange={setOpenEditProfile}>
<Modal.Content>
<div className="max-xl:px-5 py-16 w-[300px] xs:w-[380px] sm:w-[600px] md:w-auto p-2 lg:px-20">
<form
className="max-md:w-auto md:w-[672px] text-start"
onSubmit={handleSubmit(submitHandler)}
>
<div className="flex flex-col md:flex-row gap-2 w-full">
<Input
type="text"
{...register("firstName")}
label="Nome"
pattern="^[A-Za-zÀ-ÿ ,.'-]+$"
defaultValue={userCurrent.firstName}
/>
<Input
type="text"
{...register("lastName")}
label="Sobrenome"
pattern="^[A-Za-zÀ-ÿ ,.'-]+$"
defaultValue={userCurrent.lastName ?? ""}
/>
</div>
<div className="flex flex-col gap-2">
<Input
type="text"
{...register("jobTitle")}
label="Profissão"
pattern="^[A-Za-zÀ-ÿ ,.'-]+$"
defaultValue={userCurrent.jobTitle ?? ""}
/>
<Textarea
{...register("biography")}
label="Bio"
defaultValue={userCurrent.biography ?? ""}
/>
<Textarea
{...register("description")}
label="Experiência"
defaultValue={userCurrent.description ?? ""}
/>
<SelectLocation
onSelect={handleLocationChange(setSelectedCountry)}
name="country"
label="Pais"
requiredField={true}
options={countries}
placeholder="Selecione um Pais"
value={
selectedCountry || {
label: userCurrent.country,
value: userCurrent.country,
}
}
}
/>
<SelectLocation
onSelect={handleLocationChange(setSelectedStates)}
label="Estado"
name="state"
requiredField={true}
options={states}
placeholder="Selecione um Estado"
value={
selectedStates || {
label: userCurrent.state,
value: userCurrent.state,
/>
<SelectLocation
onSelect={handleLocationChange(setSelectedStates)}
label="Estado"
name="state"
requiredField={true}
options={states}
placeholder="Selecione um Estado"
value={
selectedStates || {
label: userCurrent.state,
value: userCurrent.state,
}
}
}
isDisabled={selectedCountry?.value !== "Brasil"}
/>
<Input
label="Linkedin"
{...register("linkedin")}
placeholder="linkedin.com/in/usuario1"
defaultValue={userCurrent.linkedin ?? ""}
/>
<Input
{...register("github")}
label="Portifólio/Github"
placeholder="portfóliousuário.com.br"
defaultValue={userCurrent.github ?? ""}
/>
<Input
type="number"
max={45}
min={0}
{...register("yearsOfExperience")}
label="Anos experiência"
required
defaultValue={
userCurrent.yearsOfExperience
? userCurrent.yearsOfExperience.toString()
: "0"
}
/>
<SelectSkillsInput
label="Especialização"
state={[selectedSkills, setSelectedSkills]}
options={options}
/>
</div>
<Button
type="submit"
className="mt-7"
disabled={loading}
isLoading={loading}
>
Salvar
</Button>
</form>
</div>
</Modal>
isDisabled={selectedCountry?.value !== "Brasil"}
/>
<Input
label="Linkedin"
{...register("linkedin")}
placeholder="linkedin.com/in/usuario1"
defaultValue={userCurrent.linkedin ?? ""}
/>
<Input
{...register("github")}
label="Portifólio/Github"
placeholder="portfóliousuário.com.br"
defaultValue={userCurrent.github ?? ""}
/>
<Input
type="number"
max={45}
min={0}
{...register("yearsOfExperience")}
label="Anos experiência"
required
defaultValue={
userCurrent.yearsOfExperience
? userCurrent.yearsOfExperience.toString()
: "0"
}
/>
<SelectSkillsInput
label="Especialização"
state={[selectedSkills, setSelectedSkills]}
options={options}
/>
</div>
<Button
type="submit"
className="mt-7"
disabled={loading}
isLoading={loading}
>
Salvar
</Button>
</form>
</div>
</Modal.Content>
</Modal.Root>
);
};

Expand Down
Loading