Skip to content

Commit

Permalink
feat: added update missing person status
Browse files Browse the repository at this point in the history
  • Loading branch information
darklight9811 committed Sep 12, 2024
1 parent d4539b0 commit c4bbc89
Show file tree
Hide file tree
Showing 35 changed files with 369 additions and 184 deletions.
20 changes: 10 additions & 10 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,36 @@
"postinstall": "cd ../../ && bun run postinstall"
},
"dependencies": {
"@clerk/localizations": "^2.8.1",
"@clerk/nextjs": "^5.4.1",
"@clerk/localizations": "^3.0.1",
"@clerk/nextjs": "^5.5.2",
"@react-pdf/renderer": "^3.4.4",
"@repo/ds": "1.0.0",
"@repo/env": "1.0.0",
"@repo/schemas": "1.0.0",
"@repo/services": "1.0.0",
"@tanstack/react-query": "^5.54.1",
"@tanstack/react-query-devtools": "^5.54.1",
"@tanstack/react-query": "^5.55.4",
"@tanstack/react-query-devtools": "^5.55.4",
"@upstash/ratelimit": "^2.0.2",
"@vercel/analytics": "^1.3.1",
"@vercel/functions": "^1.4.1",
"@vercel/kv": "^2.0.0",
"@vercel/speed-insights": "^1.0.12",
"@yamiassu/shared": "*",
"lucide-react": "^0.438.0",
"next": "^14.2.8",
"next-intl": "^3.19.0",
"lucide-react": "^0.439.0",
"next": "^14.2.10",
"next-intl": "^3.19.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"zod": "^3.23.8"
},
"devDependencies": {
"@repo/config": "0.0.0",
"@types/node": "^22.5.3",
"@types/node": "^22.5.4",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"autoprefixer": "^10.4.20",
"postcss": "^8.4.45",
"tailwindcss": "^3.4.10",
"typescript": "^5.5.4"
"tailwindcss": "^3.4.11",
"typescript": "^5.6.2"
}
}
9 changes: 5 additions & 4 deletions apps/app/src/app/(app)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default function Page() {
<div className="container mx-auto flex flex-col md:flex-row gap-10">
<div className="w-full sm:w-1/2">
<Image
loading="eager"
src="/images/arts/people_01.png"
alt=""
width={600}
Expand Down Expand Up @@ -114,13 +115,13 @@ export default function Page() {
<Image
src="/images/screenshots/app_store.png"
alt=""
width={120}
width={136}
height={40}
/>
<Image
src="/images/screenshots/play_store.png"
alt=""
width={120}
width={136}
height={40}
className="opacity-50"
/>
Expand Down Expand Up @@ -252,9 +253,9 @@ export default function Page() {
*/}

<div className="md:mb-32">
<h1 className="text-slate-900 text-2xl md:text-6xl font-extrabold text-center">
<h2 className="text-slate-900 text-2xl md:text-6xl font-extrabold text-center">
Perguntas frequentes
</h1>
</h2>

<Accordion
type="single"
Expand Down
83 changes: 35 additions & 48 deletions apps/app/src/app/(app)/profiles/[id]/edit/page.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import { Link } from "@/lib/navigation";
import parallel from "@/lib/parallel";
import DeleteModal from "@/modules/general/dialogs/delete-dialog";
import * as actions from "@/modules/profile/actions";
import ProfileForm from "@/modules/profile/components/profile-form";
import FindDialog from "@/modules/profile/dialogs/find-dialog";
import { currentUser } from "@/modules/user/loaders";
import Form from "@repo/ds/form/form";
import { Button, buttonVariants } from "@repo/ds/ui/button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@repo/ds/ui/dialog";
import type { ProfileUpdateSchema } from "@repo/schemas/profile";
import type {
ProfileFindSchema,
ProfileUpdateSchema,
} from "@repo/schemas/profile";
import profileService from "@repo/services/profile";
import { Eye, Trash } from "lucide-react";
import { Eye, SaveIcon, Trash } from "lucide-react";
import { notFound } from "next/navigation";

export default async function Page({ params }: { params: { id: string } }) {
Expand All @@ -33,6 +28,12 @@ export default async function Page({ params }: { params: { id: string } }) {
return actions.update({ id: params.id, data: data as ProfileUpdateSchema });
}

async function find(data: ProfileFindSchema) {
"use server";

return actions.find({ id: params.id, data });
}

async function remove() {
"use server";

Expand All @@ -52,45 +53,31 @@ export default async function Page({ params }: { params: { id: string } }) {
>
<Eye />
</Link>
<Dialog>
<DialogTrigger asChild>
<Button variant="destructive" size="icon" type="button">
<Trash />
</Button>
</DialogTrigger>

<DialogContent>
<DialogHeader>
<DialogTitle>Você tem certeza?</DialogTitle>
<DialogDescription>
Essa ação não é reversivel, os dados serão perdidos
permanentemente
</DialogDescription>
</DialogHeader>

<DialogFooter>
<DialogTrigger asChild>
<Button variant="outline">Voltar</Button>
</DialogTrigger>
<Form onSubmit={remove}>
<Button variant="destructive" className="ml-auto">
Apagar
</Button>
</Form>
</DialogFooter>
</DialogContent>
</Dialog>
<DeleteModal submit={remove}>
<Button variant="destructive" size="icon">
<Trash />
</Button>
</DeleteModal>
</h1>

<ProfileForm onSubmit={update} data={data}>
<Link
href="/profiles"
className={buttonVariants({ variant: "outline" })}
>
Voltar
</Link>
<Button type="submit" className="w-full md:max-w-[180px]">
Atualizar
<DeleteModal submit={remove}>
<Button variant="destructive" size="icon">
<Trash />
</Button>
</DeleteModal>
<FindDialog submit={find}>
<Button
size="icon"
variant="success"
disabled={!!data.date_found}
className="w-full md:max-w-[180px]"
>
Encontrado
</Button>
</FindDialog>
<Button type="submit" size="icon">
<SaveIcon />
</Button>
</ProfileForm>
</main>
Expand Down
24 changes: 9 additions & 15 deletions apps/app/src/app/(app)/profiles/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Link } from "@/lib/navigation";
import parallel from "@/lib/parallel";
import { baseUrl } from "@/lib/url";
import Banner from "@/modules/profile/components/banner";
import ReportDialog from "@/modules/report/components/report-dialog";
import { ContactDialog } from "@/modules/profile/dialogs/contact-dialog";
import ReportDialog from "@/modules/report/dialogs/report-dialog";
import { currentUser } from "@/modules/user/loaders";
import { Avatar, AvatarFallback, AvatarImage } from "@repo/ds/ui/avatar";
import { Button, buttonVariants } from "@repo/ds/ui/button";
Expand All @@ -27,7 +28,6 @@ import { getLocale, getTranslations } from "next-intl/server";
import { headers } from "next/headers";
import Image from "next/image";
import { notFound } from "next/navigation";
import { FindDialog } from "./_components/find-dialog";

/**
* ### MARK: Metadata
Expand Down Expand Up @@ -118,23 +118,17 @@ export default async function Page({ params }: { params: { id: string } }) {
</div>

<div className="flex gap-2 mt-4">
<FindDialog contact={data.contact}>
<Button type="button" className="w-full">
{t("found")}
</Button>
</FindDialog>
<ContactDialog contact={data.contact}>
<Button className="w-full">{t("found")}</Button>
</ContactDialog>
<Tooltip>
{!canReport && (
<TooltipContent>{t("already_reported")}</TooltipContent>
)}
<TooltipTrigger asChild>
<div>
<ReportDialog data={{ id_profile: data.id }}>
<Button
type="button"
variant="destructive"
disabled={!canReport}
>
<Button variant="destructive" disabled={!canReport}>
<Flag />
</Button>
</ReportDialog>
Expand All @@ -148,7 +142,7 @@ export default async function Page({ params }: { params: { id: string } }) {
link={`${baseUrl()}/profiles/${data.id}`}
description={t("help", { profile: data.name })}
>
<Button type="button" size="icon">
<Button size="icon">
<Share2 />
</Button>
</Share>
Expand All @@ -157,7 +151,7 @@ export default async function Page({ params }: { params: { id: string } }) {
description={data.description}
contact={data.contact?.options as { type: string; value: string }[]}
>
<Button type="button" size="icon">
<Button size="icon">
<Printer />
</Button>
</Banner>
Expand All @@ -172,7 +166,7 @@ export default async function Page({ params }: { params: { id: string } }) {
>
<Edit />
</Link>
<Button type="button" size="icon" variant="destructive">
<Button size="icon" variant="destructive">
<Trash />
</Button>
</>
Expand Down
1 change: 0 additions & 1 deletion apps/app/src/app/(app)/profiles/_components/filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export function Filter(props: Props) {
Aplicar
</Button>
<Button
type="button"
size="icon"
variant="destructive"
className="px-2"
Expand Down
4 changes: 1 addition & 3 deletions apps/app/src/app/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ export default function ErrorPage({
)}

<div className="flex gap-2">
<Button type="button" onClick={reset}>
Tentar novamente
</Button>
<Button onClick={reset}>Tentar novamente</Button>
<Link href="/" className={buttonVariants()}>
Ir para home
</Link>
Expand Down
2 changes: 1 addition & 1 deletion apps/app/src/components/share.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function Share(props: Props) {
return (
<DialogDrawer>
<DialogDrawerTrigger asChild>
{props.children || <Button type="button">Compartilhar</Button>}
{props.children || <Button>Compartilhar</Button>}
</DialogDrawerTrigger>

<DialogDrawerContent
Expand Down
48 changes: 48 additions & 0 deletions apps/app/src/modules/general/dialogs/delete-dialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Form from "@repo/ds/form/form";
import { Button } from "@repo/ds/ui/button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@repo/ds/ui/dialog";

interface Props {
submit: () => Promise<unknown>;
children: React.ReactNode;

title?: string;
description?: string;
}

export default function DeleteDialog(props: Props) {
return (
<Dialog>
<DialogTrigger asChild>{props.children}</DialogTrigger>

<DialogContent>
<DialogHeader>
<DialogTitle>{props.title || "Você tem certeza?"}</DialogTitle>
<DialogDescription>
{props.description ||
"Essa ação não é reversivel, os dados serão perdidos permanentemente"}
</DialogDescription>
</DialogHeader>

<DialogFooter>
<DialogTrigger asChild>
<Button variant="outline">Voltar</Button>
</DialogTrigger>
<Form onSubmit={props.submit}>
<Button variant="destructive" className="ml-auto">
Apagar
</Button>
</Form>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
20 changes: 16 additions & 4 deletions apps/app/src/modules/profile/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import api, { apiService } from "@/lib/api";
import pagination from "@repo/schemas/pagination";
import { profileStoreSchema, profileUpdateSchema } from "@repo/schemas/profile";
import { profileFindSchema, profileStoreSchema, profileUpdateSchema } from "@repo/schemas/profile";
import profileService from "@repo/services/profile";
import { revalidatePath } from "next/cache";
import { z } from "zod";

export const index = api
Expand All @@ -20,9 +21,20 @@ export const store = api
export const update = api
.zod(z.object({ id: z.string().cuid(), data: profileUpdateSchema }))
.action(apiService(profileService.update))
.action(async () => ({
reload: true,
}));
.action(async () => {
revalidatePath("/", "layout")

return { message: "yay" }
});

export const find = api
.zod(z.object({ data: profileFindSchema, id: z.string() }))
.action(apiService(profileService.find))
.action(async () => {
revalidatePath("/", "layout")

return { message: "yay" }
});

export const remove = api
.zod(z.string())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default function ProfileFormContact() {
className="m-0 w-full"
render={({ field }) => <Input {...field} />}
/>
<Button type="button" onClick={remove} variant="destructive">
<Button onClick={remove} variant="destructive">
<Trash />
</Button>
</div>
Expand Down
Loading

0 comments on commit c4bbc89

Please sign in to comment.