Skip to content

Commit

Permalink
API modifications'
Browse files Browse the repository at this point in the history
  • Loading branch information
pacholoamit committed Jul 2, 2022
1 parent b56ab87 commit e9fb005
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 18 deletions.
5 changes: 4 additions & 1 deletion web/api/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ const apiUrl = process.env.API_URL || "http://localhost:8081";
// For useSWR
const fetcher = (url: string) => axios.get(url).then((res) => res.data);

export { apiUrl, fetcher };
const apiInstance = axios.create({
baseURL: process.env.API_URL || "http://localhost:8081",
});
export { apiUrl, fetcher, apiInstance };
5 changes: 5 additions & 0 deletions web/api/dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ export type Task = {
};

export type Tasks = Task[];

export type CreateProjectRequest = {
name: string;
description: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ const NavbarButton: React.FC<NavbarButtonProps> = ({
<ThemeIcon color={color} variant="light">
{icon}
</ThemeIcon>
<Text size="sm">{label}</Text>
<Text lineClamp={1} size="sm">
{label}
</Text>
</Group>
</UnstyledButton>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Navbar, Title } from "@mantine/core";
import { useModals } from "@mantine/modals";
import { FolderPlus, Note } from "tabler-icons-react";

import NavbarButton from "../components/navbar.button";
import NavbarButton from "../navbar.button";

const ActionsSection: React.FC = () => {
const modals = useModals();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NavbarButton from "../components/navbar.button";
import NavbarButton from "../navbar.button";
import Link from "next/link";
import {
Title,
Expand Down
18 changes: 6 additions & 12 deletions web/hooks/useCreateProject.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import { useMutation } from "react-query";
import { Project } from "../api/dto";
import api from "../config/api";
import { apiInstance } from "../api/config";
import { CreateProjectRequest, Project } from "../api/dto";

interface CreateProjectArgs {
name: string;
description: string;
}

const createProject = ({ name, description }: CreateProjectArgs) => {
return api
const createProject = ({ name, description }: CreateProjectRequest) => {
return apiInstance
.post("/project", { name, description })
.then((res) => res.data) as Promise<Project>;
};

const useCreateProject = () => {
return useMutation(
(formData: CreateProjectArgs) => createProject(formData),
{}
return useMutation((formData: CreateProjectRequest) =>
createProject(formData)
);
};

Expand Down
4 changes: 4 additions & 0 deletions web/hooks/useCreateTask.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface CreateTaskArgs {
name: string;
description: string;
}
2 changes: 1 addition & 1 deletion web/hooks/useGetAllTasksByProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface useGetAllTasksByProjectProps {

const useGetAllTasksByProject = ({ id }: useGetAllTasksByProjectProps) => {
const url = `${apiUrl}/project/${id}/tasks`;
const { data, error } = useSWR<Tasks>(id ? url : null, id ? fetcher : null);
const { data, error } = useSWR<Tasks>(url, fetcher);

return {
tasks: data,
Expand Down
2 changes: 1 addition & 1 deletion web/hooks/useGetProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface useGetProjectProps {

const useGetProject = ({ id }: useGetProjectProps) => {
const url = `${apiUrl}/project/${id}`;
const { data, error } = useSWR<Project>(id ? url : null, id ? fetcher : null);
const { data, error } = useSWR<Project>(url, fetcher);
return {
project: data,
isLoading: !error && !data,
Expand Down

0 comments on commit e9fb005

Please sign in to comment.