-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
52 changed files
with
2,171 additions
and
2,497 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,53 @@ | ||
import { api } from '@/libs/fetch-api' | ||
import { cookies as nextCookies } from 'next/headers' | ||
|
||
export type UserProfile = { | ||
id: string | ||
name: string | ||
aboutMe: string | null | ||
seniority: string | ||
role: string | ||
avatar_url: string | ||
state: string | ||
city: string | ||
country: string | ||
overallRate: string | ||
slugProfile: string | ||
linkedinLink: string | ||
githubLink: string | ||
title: string | ||
skills: Array<string> | ||
updatedAt: string | ||
involvedProjects: Array<{ | ||
id: string | ||
image_url: string | ||
name: string | ||
status: 'inProgress' | 'recruiting' | 'closed' | ||
}> | ||
projectRealized: Array<{ id: string }> | ||
} | ||
|
||
type GetUserResponse = { | ||
user: UserProfile | null | ||
} | ||
|
||
export async function getUserProfile({ | ||
slug, | ||
}: { | ||
slug: string | ||
}): Promise<GetUserResponse> { | ||
const cookies = nextCookies() | ||
|
||
const response = await api(`/account/user/me/${slug}`, { | ||
headers: { | ||
Cookie: cookies.toString(), | ||
}, | ||
next: { | ||
tags: [`profile:${slug}`], | ||
}, | ||
}) | ||
|
||
const user = await response.json() | ||
|
||
return user | ||
} |
60 changes: 60 additions & 0 deletions
60
src/app/(app)/me/[slug]/components/edit-about-section/about-me-text-area.tsx
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,60 @@ | ||
import { Editor } from '@/components/editor' | ||
import { InputMessageError } from '@/components/ui/input' | ||
import { useController, useFormContext } from 'react-hook-form' | ||
|
||
interface RequirementsTextAreaProps { | ||
editable?: boolean | ||
content?: string | ||
} | ||
|
||
export function AboutMeTextArea({ | ||
editable, | ||
content, | ||
}: RequirementsTextAreaProps) { | ||
const { control } = useFormContext() | ||
|
||
const { | ||
formState: { errors }, | ||
field: { onChange, value }, | ||
} = useController({ | ||
name: 'aboutMe', | ||
control, | ||
}) | ||
|
||
const MAX_LENGTH = 1200 | ||
|
||
return ( | ||
<div className="space-y-1"> | ||
<div className="relative max-w-[704px]"> | ||
<Editor | ||
id="aboutMe" | ||
onUpdateMarkdown={(value) => { | ||
onChange(value) | ||
}} | ||
config={{ | ||
editable, | ||
maxLength: MAX_LENGTH, | ||
className: '', | ||
}} | ||
placeholderValue="Conte-nos sobre você" | ||
content={content} | ||
/> | ||
|
||
{value && ( | ||
<span | ||
data-in-limit={value.length > MAX_LENGTH} | ||
className="absolute bottom-3 right-3 text-xs font-light data-[in-limit=true]:text-red-500" | ||
> | ||
{value.length}/{MAX_LENGTH} | ||
</span> | ||
)} | ||
</div> | ||
|
||
{errors.aboutMe && ( | ||
<InputMessageError> | ||
{errors.aboutMe.message?.toString()} | ||
</InputMessageError> | ||
)} | ||
</div> | ||
) | ||
} |
147 changes: 147 additions & 0 deletions
147
src/app/(app)/me/[slug]/components/edit-about-section/index.tsx
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,147 @@ | ||
'use client' | ||
|
||
import { Button } from '@/components/ui/button' | ||
// import { Combobox } from '@/components/ui/combobox' | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogFooter, | ||
DialogTitle, | ||
// DialogTrigger, | ||
} from '@/components/ui/dialog' | ||
// import { | ||
// InputControl, | ||
// InputMessageError, | ||
// InputPrefix, | ||
// InputRoot, | ||
// } from '@/components/ui/input' | ||
import { Label } from '@/components/ui/label' | ||
import { ReactNode, useState } from 'react' | ||
import { FormProvider, useForm } from 'react-hook-form' | ||
import { AboutMeTextArea } from './about-me-text-area' | ||
import { UserProfile } from '@/actions/get-user-profile' | ||
import { z } from 'zod' | ||
import { zodResolver } from '@hookform/resolvers/zod' | ||
import { SkillsInput } from './skills-input' | ||
import { useMutation } from '@tanstack/react-query' | ||
import { api } from '@/libs/fetch-api' | ||
import { useRouter } from 'next/navigation' | ||
import { toast } from '@/components/ui/use-toast' | ||
import { Loader2 } from 'lucide-react' | ||
import dayjs from 'dayjs' | ||
|
||
const editAboutInput = z.object({ | ||
aboutMe: z | ||
.string() | ||
.max(1200, { message: 'Limite máximo de 1200 caracteres.' }) | ||
.optional(), | ||
skills: z.array(z.string(), { required_error: 'Select a technology' }), | ||
}) | ||
|
||
export type EditAboutInput = z.infer<typeof editAboutInput> | ||
|
||
type EditaPersonalSectionProps = { | ||
children: ReactNode | ||
user: Pick<UserProfile, 'aboutMe' | 'skills' | 'slugProfile' | 'updatedAt'> | ||
} | ||
|
||
export function EditAboutSection({ | ||
children, | ||
user, | ||
}: EditaPersonalSectionProps) { | ||
const router = useRouter() | ||
const [open, setOpen] = useState(false) | ||
|
||
const form = useForm<EditAboutInput>({ | ||
resolver: zodResolver(editAboutInput), | ||
defaultValues: { | ||
aboutMe: user.aboutMe ?? '', | ||
skills: user.skills ?? [], | ||
}, | ||
}) | ||
|
||
const { | ||
handleSubmit, | ||
|
||
formState: { isSubmitting }, | ||
} = form | ||
|
||
const { mutateAsync, isPending } = useMutation({ | ||
mutationFn: async ({ skills, aboutMe }: EditAboutInput) => { | ||
await api(`/account/user/me/${user.slugProfile}/about/save`, { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
skills, | ||
aboutMe, | ||
}), | ||
}) | ||
}, | ||
}) | ||
|
||
async function handleEditAbout(data: EditAboutInput) { | ||
try { | ||
await mutateAsync(data) | ||
setOpen(false) | ||
|
||
router.refresh() | ||
} catch (error) { | ||
console.error(error) | ||
|
||
return toast({ | ||
title: 'Ocorreu um error ao salvar suas informações.', | ||
description: `Tente novamente mais tarde.`, | ||
variant: 'destructive', | ||
}) | ||
} | ||
} | ||
|
||
return ( | ||
<Dialog open={open} onOpenChange={setOpen}> | ||
{children} | ||
<DialogContent> | ||
<DialogTitle>Editar perfil</DialogTitle> | ||
|
||
<FormProvider {...form}> | ||
<form | ||
id="edit-about" | ||
className="space-y-6" | ||
onSubmit={handleSubmit(handleEditAbout)} | ||
> | ||
<div className="space-y-3.5"> | ||
<Label htmlFor="aboutMe">Sobre</Label> | ||
|
||
<AboutMeTextArea | ||
content={user.aboutMe ?? ''} | ||
editable={!isSubmitting || !isPending} | ||
/> | ||
</div> | ||
|
||
<div className="space-y-3.5"> | ||
<Label htmlFor="technologies">Habilidades</Label> | ||
|
||
<SkillsInput disabled={isSubmitting || isPending} /> | ||
</div> | ||
</form> | ||
</FormProvider> | ||
|
||
<DialogFooter> | ||
<Button | ||
form="edit-about" | ||
type="submit" | ||
className="w-full max-w-[10.8125rem]" | ||
> | ||
{isPending || isSubmitting ? ( | ||
<Loader2 className="animate-spin" size={16} /> | ||
) : ( | ||
'Salvar alterações' | ||
)} | ||
</Button> | ||
<span className="block text-xs text-muted-foreground"> | ||
Última alteração realizada em{' '} | ||
{dayjs(user.updatedAt).format('DD/MM/YYYY')} | ||
</span> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
) | ||
} |
Oops, something went wrong.