Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
226 changes: 210 additions & 16 deletions src/app/[language]/projetos/[id]/page-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
import { useState } from "react";
import { useParams } from "next/navigation";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { ArrowLeft, Lightbulb } from "lucide-react";
import {
ArrowLeft,
ExternalLink,
Lightbulb,
Megaphone,
Star,
} from "lucide-react";
import {
useDeleteProjectInterestService,
useGetMyProjectInterestService,
useGetProjectGroupService,
useGetProjectIdeaService,
useGetProjectParticipantsService,
usePatchProjectFeatureService,
usePostProjectCallService,
usePutProjectInterestService,
} from "@/services/api/services/projects";
import HTTP_CODES_ENUM from "@/services/api/types/http-codes";
Expand All @@ -26,6 +35,8 @@
import { useSnackbar } from "@/hooks/use-snackbar";
import { cn, getApiError } from "@/lib/utils";
import { projectUserName } from "@/lib/project-labels";
import { RoleEnum } from "@/services/api/types/role";
import { FIELD_CLASS } from "../project-components";

const MAX_STACK = 7;

Expand Down Expand Up @@ -98,6 +109,96 @@
);
}

/** Quem propôs chama os interessados e passa o link do grupo. */
function CallInterestedPanel({
idea,
onDone,
}: {
idea: ProjectIdea;
onDone: () => void;
}) {

Check warning on line 119 in src/app/[language]/projetos/[id]/page-content.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Mark the props of the component as read-only.

See more on https://sonarcloud.io/project/issues?id=devs-tocantins_front-engajamento&issues=AaGFKRdqkO4PQjLUcJ7c&open=AaGFKRdqkO4PQjLUcJ7c&pullRequest=64
const { enqueueSnackbar } = useSnackbar();
const postCall = usePostProjectCallService();
const [open, setOpen] = useState(false);
const [groupLink, setGroupLink] = useState("");
const [message, setMessage] = useState("");
const [sending, setSending] = useState(false);

const handleSubmit = async () => {
setSending(true);
try {
const { status, data } = await postCall({
ideaId: idea.id,
groupLink: groupLink.trim(),
message: message.trim() || undefined,
});
if (status === HTTP_CODES_ENUM.OK || status === HTTP_CODES_ENUM.CREATED) {
enqueueSnackbar(
`Chamada enviada para ${data.notified} ${
data.notified === 1 ? "pessoa" : "pessoas"
}.`,
{ variant: "success" }
);
setOpen(false);
setMessage("");
onDone();
} else {
enqueueSnackbar(getApiError(data, "Erro ao chamar os interessados."), {
variant: "error",
});
}
} finally {
setSending(false);
}
};

if (!open) {
return (
<Button
variant="outline"
onClick={() => setOpen(true)}
className="h-12 gap-2 px-[22px] text-[15px]"
>
<Megaphone className="size-4" />
{idea.calledAt ? "Chamar de novo" : "Chamar interessados"}
</Button>
);
}

return (
<div className="flex w-full max-w-[560px] flex-col gap-3 rounded-xl border border-border bg-card p-4">
<p className="text-sm text-muted-foreground">
Crie um grupo (WhatsApp, Discord...) e cole o link aqui. Todo mundo que
marcou interesse recebe um aviso e vê o botão para entrar.
</p>
<input
type="url"
value={groupLink}
onChange={(event) => setGroupLink(event.target.value)}
placeholder="https://chat.whatsapp.com/..."
className={FIELD_CLASS}
maxLength={300}
/>
<textarea
value={message}
onChange={(event) => setMessage(event.target.value)}
placeholder="Recado opcional (ex.: vamos começar sábado às 9h)"
className={FIELD_CLASS}
rows={2}
maxLength={300}
/>
<div className="flex gap-2">
<Button onClick={handleSubmit} disabled={sending || !groupLink.trim()}>
{sending ? "Enviando..." : "Enviar chamada"}
</Button>
<Button variant="ghost" onClick={() => setOpen(false)}>
Cancelar
</Button>
</div>
</div>
);
}

function InterestSection({ idea }: { idea: ProjectIdea }) {
const { user, isLoaded } = useAuth();
const { enqueueSnackbar } = useSnackbar();
Expand All @@ -107,7 +208,9 @@
const putInterest = usePutProjectInterestService();
const deleteInterest = useDeleteProjectInterestService();

const getGroup = useGetProjectGroupService();
const [processing, setProcessing] = useState(false);
const isAuthor = !!user && Number(user.id) === idea.authorId;

const { data: participants = [], isLoading } = useQuery({
queryKey: ["project-idea-participants", idea.id],
Expand All @@ -127,6 +230,17 @@
enabled: !!user,
});

const canSeeGroup =
!!user && !!idea.calledAt && (isAuthor || !!mine?.interested);
const { data: group } = useQuery({
queryKey: ["project-idea-group", idea.id],
queryFn: async () => {
const { status, data } = await getGroup({ ideaId: idea.id });
return status === HTTP_CODES_ENUM.OK ? data : null;
},
enabled: canSeeGroup,
});

// Uma pessoa por linha, mesmo que tenha marcado interesse mais de uma vez.
const people = participants.filter(
(participant, index, list) =>
Expand All @@ -142,6 +256,9 @@
queryKey: ["my-project-interest", idea.id],
});
queryClient.invalidateQueries({ queryKey: ["project-idea", idea.id] });
queryClient.invalidateQueries({
queryKey: ["project-idea-group", idea.id],
});
};

const handleToggle = async () => {
Expand Down Expand Up @@ -202,14 +319,32 @@
quem propôs chama o grupo e vocês se organizam juntos.
</p>
</div>
<Button
variant={joined ? "outline" : "default"}
onClick={handleToggle}
disabled={processing}
className="h-12 px-[22px] text-[15px]"
>
{joined ? "Remover meu interesse" : "Tenho interesse"}
</Button>
<div className="flex flex-wrap items-center gap-3">
{group?.groupLink && (
<Button
render={
<a
href={group.groupLink}
target="_blank"
rel="noopener noreferrer"
/>
}
className="h-12 gap-2 px-[22px] text-[15px]"
>
<ExternalLink className="size-4" />
Entrar no grupo
</Button>
)}
{isAuthor && <CallInterestedPanel idea={idea} onDone={refresh} />}
<Button
variant={joined ? "outline" : "default"}
onClick={handleToggle}
disabled={processing}
className="h-12 px-[22px] text-[15px]"
>
{joined ? "Remover meu interesse" : "Tenho interesse"}
</Button>
</div>
</div>

{isLoading ? (
Expand Down Expand Up @@ -253,10 +388,60 @@
);
}

/** Só moderação: escolhe qual é o projeto da vez. */
function FeatureToggle({ idea }: { idea: ProjectIdea }) {

Check warning on line 392 in src/app/[language]/projetos/[id]/page-content.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Mark the props of the component as read-only.

See more on https://sonarcloud.io/project/issues?id=devs-tocantins_front-engajamento&issues=AaGFKRdqkO4PQjLUcJ7d&open=AaGFKRdqkO4PQjLUcJ7d&pullRequest=64
const { enqueueSnackbar } = useSnackbar();
const queryClient = useQueryClient();
const patchFeature = usePatchProjectFeatureService();
const [saving, setSaving] = useState(false);
const featured = !!idea.featuredAt;

const handleClick = async () => {
setSaving(true);
try {
const { status, data } = await patchFeature({
ideaId: idea.id,
featured: !featured,
});
if (status === HTTP_CODES_ENUM.OK) {
enqueueSnackbar(
featured ? "Destaque removido." : "Agora é o projeto da vez!",
{ variant: "success" }
);
queryClient.invalidateQueries({ queryKey: ["project-idea", idea.id] });
queryClient.invalidateQueries({ queryKey: ["public-project-ideas"] });
} else {
enqueueSnackbar(getApiError(data, "Erro ao atualizar o destaque."), {
variant: "error",
});
}
} finally {
setSaving(false);
}
};

return (
<Button
variant="outline"
size="sm"
onClick={handleClick}
disabled={saving}
className="w-fit gap-2"
>
<Star className="size-4" />
{featured ? "Remover de projeto da vez" : "Marcar como projeto da vez"}
</Button>
);
}

function ProjectIdeaDetailPageContent() {
const params = useParams();
const id = params.id as string;
const fetchIdea = useGetProjectIdeaService();
const { user } = useAuth();
const isModerator =
!!user?.role &&
[RoleEnum.ADMIN, RoleEnum.MODERATOR].includes(Number(user.role.id));

const { data: idea, isLoading } = useQuery({
queryKey: ["project-idea", id],
Expand Down Expand Up @@ -304,14 +489,21 @@
</Link>

<div className="flex max-w-[860px] flex-col gap-4">
{open && (
<span className="inline-flex w-fit items-center gap-2 rounded-full bg-emerald-500/10 px-3 py-1.5 text-xs font-semibold text-emerald-400">
<span
aria-hidden="true"
className="size-[7px] rounded-full bg-emerald-400"
/>
Aberto a interessados
{idea.featuredAt ? (
<span className="inline-flex w-fit items-center gap-2 rounded-full bg-amber-500/10 px-3 py-1.5 text-xs font-semibold text-amber-400">
<Star aria-hidden="true" className="size-3.5" />
Projeto da vez
</span>
) : (
open && (
<span className="inline-flex w-fit items-center gap-2 rounded-full bg-emerald-500/10 px-3 py-1.5 text-xs font-semibold text-emerald-400">
<span
aria-hidden="true"
className="size-[7px] rounded-full bg-emerald-400"
/>
Aberto a interessados
</span>
)
)}
<h1 className="text-[28px] font-bold leading-[1.1] tracking-tight sm:text-[44px]">
{idea.title}
Expand Down Expand Up @@ -340,6 +532,8 @@
</span>
</div>

{isModerator && open && <FeatureToggle idea={idea} />}

{idea.tags.length > 0 && (
<div className="flex flex-wrap gap-2">
{idea.tags.map((tag) => (
Expand Down
14 changes: 7 additions & 7 deletions src/app/[language]/projetos/page-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const TABS: Record<Tab, { label: string; icon: typeof Lightbulb }> = {

function CardSkeletons() {
return (
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
{Array.from({ length: 6 }).map((_, i) => (
<div key={i} className="h-44 animate-pulse rounded-lg bg-muted" />
<div className="flex flex-col gap-4">
{Array.from({ length: 4 }).map((_, i) => (
<div key={i} className="h-36 animate-pulse rounded-lg bg-muted" />
))}
</div>
);
Expand Down Expand Up @@ -100,7 +100,7 @@ function IdeasList() {

return (
<>
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
<div className="flex flex-col gap-4">
{ideas.map((idea) => (
<IdeaCard key={idea.id} idea={idea} />
))}
Expand Down Expand Up @@ -200,7 +200,7 @@ function ProjectsPageContent() {
const [tab, setTab] = useState<Tab>("ideias");

return (
<div className="mx-auto max-w-6xl px-4 py-10 pb-20">
<div className="mx-auto w-full max-w-[1600px] px-4 py-10 pb-20 sm:px-8">
<div className="mb-7 flex flex-wrap items-end justify-between gap-4">
<div>
<p className="mb-2 font-heading text-xs font-semibold uppercase tracking-wider text-primary">
Expand All @@ -210,8 +210,8 @@ function ProjectsPageContent() {
Projetos da comunidade
</h1>
<p className="mt-2 max-w-xl text-[15px] leading-relaxed text-muted-foreground">
Proponha uma ideia, veja quem quer participar e monte um time com as
pessoas certas para cada cargo.
Proponha uma ideia, marque interesse nas que você quer ver acontecer
e acompanhe quem vai participar.
</p>
</div>
<div className="flex gap-2">
Expand Down
Loading
Loading