Skip to content

Commit

Permalink
chore: small changes + removing unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
Amama-Fatima committed Jun 24, 2024
1 parent 374d9d8 commit 92873cd
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 332 deletions.
12 changes: 9 additions & 3 deletions src/app/(lobby)/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getUser } from '@/lib/server-user';
import { createSupabaseServerClient } from '@/lib/supabase/server-clients';

import { DashboardGraph } from '@/components/dashboard-graph';
import DashboardTaskCard from '@/components/dashboard-task-card';
import TaskList from '@/components/task-list';
import {
Card,
CardContent,
Expand Down Expand Up @@ -72,12 +72,18 @@ export default async function DashboardPage() {
<CardTitle>Tasks</CardTitle>
<CardDescription>Following are your ongoing tasks.</CardDescription>
<CardContent className='flex flex-col gap-4'>
{tasksDataWithProjectName?.map((taskWithProjectName, index) => (
{tasksDataWithProjectName?.length === 0 && (
<p className='text-muted-foreground text-center'>
No tasks found
</p>
)}
{/* {tasksDataWithProjectName?.map((taskWithProjectName, index) => (
<DashboardTaskCard
taskWithProjectName={taskWithProjectName}
key={index}
/>
))}
))} */}
<TaskList tasksDataWithProjectName={tasksDataWithProjectName} />
</CardContent>
</CardHeader>
</Card>
Expand Down
4 changes: 3 additions & 1 deletion src/app/(lobby)/dashboard/projects/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';

import { projectSchemaType } from '@/lib/schemas';
import { getRole } from '@/lib/server-user';
import { createSupabaseServerClient } from '@/lib/supabase/server-clients';

import AllProjects from '@/components/all-projects';
Expand All @@ -13,6 +14,7 @@ export default async function ProjectPage() {
} = await serverSupabase.auth.getUser();
if (user) {
const user_id = user?.id;
const role = await getRole(user_id);
//get teams
const { data: teamsIds } = await serverSupabase
.from('teams-members')
Expand All @@ -31,7 +33,7 @@ export default async function ProjectPage() {
const projectsTableData = projects as projectSchemaType[];
return (
<div className='flex flex-col gap-3'>
<CreateProjectForm />
{role === 'TEAM_HEAD' && <CreateProjectForm />}
<AllProjects projects={projectsTableData} />
</div>
);
Expand Down
8 changes: 8 additions & 0 deletions src/app/(lobby)/inbox/[team]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ export default async function TeamInboxPage({ params }: TeamInboxPageProps) {
.select('*')
.eq('name', decodedTeamName);

if (!teamData || teamData.length === 0) {
return (
<p className='text-center text-lg text-muted-foreground'>
Team not found
</p>
);
}

const team_id = teamData && teamData[0].team_id;

const { data: oldChat } = await serverSupabase
Expand Down
23 changes: 0 additions & 23 deletions src/app/my-profile/[name]/register-member/page.tsx

This file was deleted.

20 changes: 0 additions & 20 deletions src/components/Skeleton.tsx

This file was deleted.

3 changes: 3 additions & 0 deletions src/components/dashboard-graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ export function DashboardGraph({ projectsByTeam }: DashboardGraphProps) {
);
}
}
if (Object.keys(projectsByTeam).length === 0) {
return <p className='text-center text-muted-foreground'>No Data</p>;
}
return (
<>
{Object.keys(teamsWithStatusCounts).map((teamName, index) => (
Expand Down
9 changes: 2 additions & 7 deletions src/components/forms/create-project-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export default function CreateProjectForm() {
const session = useSession();
const user_id = session?.user.id;

const [isLoading, setIsLoading] = useState(false);
const [selectedteam, setSelectedTeam] = useState<string>('');

const form = useForm<projectFormSchemaType>({
Expand Down Expand Up @@ -94,20 +93,16 @@ export default function CreateProjectForm() {
mutationFn: createProject,
onSuccess: () => {
toast.success('Project Created Successfully');
setIsLoading(false);
form.reset();
setSelectedTeam('');
},
onError: () => {
toast.error('Failed to create team');
setIsLoading(false);
},
});

const onSubmit: SubmitHandler<projectFormSchemaType> = async (formData) => {
formData.team_id = selectedteam;

setIsLoading(true);
mutate.mutate(formData);
};

Expand Down Expand Up @@ -254,8 +249,8 @@ export default function CreateProjectForm() {
)}
/>
</div>
<Button type='submit' disabled={isLoading}>
{isLoading && (
<Button type='submit' disabled={mutate.isPending}>
{mutate.isPending && (
<Icons.spinner
className='mr-2 size-4 animate-spin'
aria-hidden='true'
Expand Down
12 changes: 4 additions & 8 deletions src/components/forms/create-team-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export default function CreateTeamForm({
isNotTeamHead,
}: CreateTeamFormProps) {
const { name } = user;
const [isLoading, setIsLoading] = useState(false);
const [membersList, setMembersList] = useState<
{ label: string; email: string; value: string }[]
>([]);
Expand Down Expand Up @@ -117,25 +116,22 @@ export default function CreateTeamForm({
return response.json();
}

const { mutate } = useMutation({
const mutate = useMutation({
mutationFn: createTeam,
onSuccess: () => {
toast.success('Team Created Successfully');
setIsLoading(false);
form.reset();
updateSelectedMembers();
increaseTeamsJoined();
},
onError: () => {
setIsLoading(false);
toast.error('Failed to create team');
},
});

const onSubmit: SubmitHandler<teamFormSchemaType> = async (formData) => {
formData.members = Array.from(selectedMembers);
setIsLoading(true);
mutate(formData);
mutate.mutate(formData);
};

return (
Expand Down Expand Up @@ -219,8 +215,8 @@ export default function CreateTeamForm({
)}
/>
{canJoinMoreTeams() ? (
<Button type='submit' disabled={isLoading || isNotTeamHead}>
{isLoading && (
<Button type='submit' disabled={mutate.isPending || isNotTeamHead}>
{mutate.isPending && (
<Icons.spinner
className='mr-2 size-4 animate-spin'
aria-hidden='true'
Expand Down
169 changes: 0 additions & 169 deletions src/components/forms/register-member-form.tsx

This file was deleted.

Loading

0 comments on commit 92873cd

Please sign in to comment.