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

Patch-user #95

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
1956885
:feat: add Refetch news id
joaoP-ribeiro Apr 10, 2024
c9024b4
:feat: create type new form
joaoP-ribeiro Apr 10, 2024
7cee8bd
:fix: variant colors
joaoP-ribeiro Apr 10, 2024
f607492
:fix: update form add news
joaoP-ribeiro Apr 10, 2024
f7462bc
:feat: alert layout
joaoP-ribeiro Apr 10, 2024
6fd40e2
:feat: layout form
joaoP-ribeiro Apr 11, 2024
e7bdd52
:fix: update remove tags
joaoP-ribeiro Apr 11, 2024
0667e88
:feat: variante user new, update and delete news
joaoP-ribeiro Apr 11, 2024
e398f18
:feat: create a function for layout form
joaoP-ribeiro Apr 11, 2024
ebde643
:fix: other training
joaoP-ribeiro Apr 11, 2024
a2cceb2
:feat: create querie delete news
joaoP-ribeiro Apr 12, 2024
b4dc6d0
:feat: download new component shadcn ui
joaoP-ribeiro Apr 12, 2024
21df26f
:fix: update design variant
joaoP-ribeiro Apr 12, 2024
11bcf20
:fix: remove console.log
joaoP-ribeiro Apr 12, 2024
349888f
:feat: type DefaultValuesType and update FormType and AlertType
joaoP-ribeiro Apr 12, 2024
f5fa177
:fix: design and component features
joaoP-ribeiro Apr 12, 2024
5e3b0e9
:fix: update features form
joaoP-ribeiro Apr 12, 2024
6ba87e5
:fix: pdate features, add MenuPopoverEditNews component
joaoP-ribeiro Apr 12, 2024
5f237fa
:feat: alert for add news in form add news
joaoP-ribeiro Apr 12, 2024
d26fdc6
:fix: add features
joaoP-ribeiro Apr 12, 2024
57ac9e9
:feat: alert delete for delete feature
joaoP-ribeiro Apr 12, 2024
350ca2e
:feat: alert update for update news feature
joaoP-ribeiro Apr 12, 2024
5b0b46b
:feat: add sahdcn ui component
joaoP-ribeiro Apr 12, 2024
8b9fa18
:fix: update design
joaoP-ribeiro Apr 22, 2024
f53bbce
:fix: update cache
joaoP-ribeiro Apr 22, 2024
e799168
:fix: update filter
joaoP-ribeiro Apr 22, 2024
2d6b590
:fix: update funtion team
joaoP-ribeiro Apr 22, 2024
c8afa98
:fix: update queries and cache
joaoP-ribeiro Apr 22, 2024
568ad6a
:fix: link page
joaoP-ribeiro Apr 22, 2024
7927b69
:fix: import
joaoP-ribeiro Apr 22, 2024
62459fe
:feat: useEffect for name page
joaoP-ribeiro Apr 22, 2024
894b807
:fix: update queries
joaoP-ribeiro Apr 23, 2024
5473d22
:feat: published news
joaoP-ribeiro Apr 23, 2024
ed4b48a
:feat: update isPublished
joaoP-ribeiro Apr 23, 2024
c9c60dd
:fix: cache refesh
joaoP-ribeiro Apr 23, 2024
55e69bb
:fix: published condition feature
joaoP-ribeiro Apr 23, 2024
7f18db0
:fix: update queries
joaoP-ribeiro Apr 24, 2024
5e33ebd
:fix: update image error loading image news
joaoP-ribeiro Apr 29, 2024
a679bc8
:feat: create querie delete comment
joaoP-ribeiro Apr 29, 2024
29f33f0
:fix: comment user list
joaoP-ribeiro Apr 29, 2024
abba5bf
:fix: archived local
joaoP-ribeiro Apr 29, 2024
6fac3da
:fix: designin body news
joaoP-ribeiro Apr 29, 2024
69582c2
:feat: user page config comments
joaoP-ribeiro Apr 29, 2024
1c5c308
Merge branch 'dev' into patch-user
joaoP-ribeiro May 14, 2024
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
97 changes: 97 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
"@azure/msal-browser": "^3.11.0",
"@azure/msal-react": "^2.0.12",
"@hookform/resolvers": "^3.3.4",
"@radix-ui/react-alert-dialog": "^1.0.5",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-context-menu": "^2.1.5",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-menubar": "^1.0.4",
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-slot": "^1.0.2",
"@tanstack/react-query": "^5.22.2",
"@tanstack/react-query-devtools": "^5.28.14",
Expand Down
Binary file added public/imageDefault.jpg
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/newsNotFound.png
Binary file not shown.
16 changes: 12 additions & 4 deletions src/api/hooks/news/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ async function getNewsFilterScroll(ctx: QueryFunctionContext) {
const filterParam = usefilter({ filters: { tags, title } });

const url = tags || title ? `${filterParam}` : undefined;

console.log(`news/preview?size=9${url}`)
const { data } = await api.get<ContentNews>(`news/preview?size=9${url}`, {
params: {
page: pageParam,
},
});

console.log(data)
return data;
}

Expand All @@ -51,7 +49,7 @@ export function useFetchGetNewsScroll(tags?: string, title?: string) {
}

// GET News By ID
async function getIdNews(ctx: QueryFunctionContext) {
export async function getIdNews(ctx: QueryFunctionContext) {
const [, id] = ctx.queryKey;
const { data } = await api.get<News>(`news/${id}`);
return data;
Expand All @@ -64,6 +62,16 @@ export function useFetchGetNewsId(id: string) {
});
}


export function useFetchGetNewsIdRefetch(id: string) {
return useQuery<News, Error>({
queryKey: ["newsRead", id],
queryFn: getIdNews,
enabled: false,
refetchOnWindowFocus: false
});
}

// GET Other News
async function getNewsOtherNews() {
const { data } = await api.get<ContentNews>(
Expand Down
135 changes: 129 additions & 6 deletions src/api/hooks/user/queries.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,140 @@
import { ContentNews } from "@/api/types/news/type";
import { ContentComment, ContentNews, News } from "@/api/types/news/type";
import api from "@/services/api";
import { useQuery } from "@tanstack/react-query";
import {
QueryFunctionContext,
useMutation,
useQuery,
useQueryClient,
} from "@tanstack/react-query";
import { title } from "process";
import toast from "react-hot-toast";
import { getIdNews } from "../news/queries";

// News
// GET user news
async function getUserNews() {
const { data } = await api.get<ContentNews>(`news/author`);
export async function getUserNews(ctx: QueryFunctionContext) {
const [, status] = ctx.queryKey;
const filter = status === undefined ? "published" : status;
const { data } = await api.get<ContentNews>(`news/author?sortBy=${filter}`);
return data;
}

export function useFetchGetUserNews() {
export function useFetchGetUserNews(status?: string) {
return useQuery<ContentNews, Error>({
queryKey: ["news"],
queryKey: ["userNews", status],
queryFn: getUserNews,
});
}

// PATCH user news
async function patchNews({
newsObject,
id,
}: {
newsObject: FormData;
id: string;
}) {
const promise = api.patch<News>(`news/${id}`, newsObject);

toast.promise(promise, {
loading: "Updated news",
success: "Updated news with success",
error: (error) => {
console.log(error);
return error.response.data
? `${error.message}:\n${error.response.data.message}`
: `${error.message}`;
},
});

return await promise;
}

export function useMutationPatchNews() {
return useMutation({
mutationFn: patchNews,
});
}

// ARCHIVE user news

async function patchArchive(id: string) {
const archive = api.patch<News>(`news/${id}/archive`);

toast.promise(archive, {
loading: "Delete news",
success: "Delete news with success",
error: (error) => {
console.log(error);
return error.response.data
? `${error.message}:\n${error.response.data.message}`
: `${error.message}`;
},
});
return await archive;
}

async function patchPublish(id: string) {
const publish = api.patch<News>(`news/${id}/publish`);

toast.promise(publish, {
loading: "Publish news",
success: "Publish news with success",
error: (error) => {
console.log(error);
return error.response.data
? `${error.message}:\n${error.response.data.message}`
: `${error.message}`;
},
});
return await publish;
}

export function useMutationPatchArchive() {
return useMutation({
mutationFn: patchArchive,
});
}

export function useMutationPatchPublish() {
return useMutation({
mutationFn: patchPublish,
});
}

// News
// GET user comments

export async function getUserComments() {
const { data } = await api.get<ContentComment>(
`comments/author`
);
return data;
}

export function useFetchGetUserComments(){
return useQuery<ContentComment, Error>({
queryKey: ["userComments"],
queryFn: getUserComments
})
}

async function patchDelete(id: number) {
const deleteComment = api.delete(`comments/${id}`);

toast.promise(deleteComment, {
loading: "Delete Comment",
success: "Delete Comment with success",
error: (error) => {
console.log(id);
return "Delete Comment Error";
},
});
return await deleteComment;
}

export function useMutationPatchDelete() {
return useMutation({
mutationFn: patchDelete,
});
}
36 changes: 36 additions & 0 deletions src/api/types/all/type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
import { ReadonlyURLSearchParams } from "next/navigation";
import { title } from "process";

export interface Error {
text: string;
Expand All @@ -21,3 +22,38 @@ export interface FilterPath {
searchParams: ReadonlyURLSearchParams;
router: AppRouterInstance;
}

export interface AlertType {
variantButton:
| "delete"
| "ghost"
| "bdpurple"
| "bdlight"
| "default"
| "outline";
nameButton: string | any;
type?: "submit" | "reset" | "button" | undefined;
title: string;
description: string;
nameButtonAction: string;
Action?: () => void;
idForm?: string;
}

interface DefaultValuesType {
title?: string;
body?: string;
image?: File | undefined;
tags?: string[];
}

export interface FormType {
title: string | any;
open: boolean;
openUpdate?: boolean;
OnSubmit: (values: any) => void;
idForm?: string;
idNews?: string;
defaultValues?: DefaultValuesType;
alertSubmit: JSX.Element
}
Loading
Loading