From b7771ac827509960231c3f974c213257b8e2d220 Mon Sep 17 00:00:00 2001 From: Andrew Trieu Date: Tue, 26 Nov 2024 10:34:29 +0200 Subject: [PATCH] feat: Update environment variable naming and refactor image URL handling across the application --- .github/workflows/amplify-deployment.yml | 6 +- tasker-client/amplify.yml | 2 +- tasker-client/next.config.ts | 12 ++- .../src/app/components/ModalNewTask/index.tsx | 76 +++++++++++-------- .../src/app/components/Navbar/index.tsx | 2 +- .../src/app/components/Sidebar/index.tsx | 4 +- .../src/app/components/TaskCard/index.tsx | 2 +- .../src/app/components/UserCard/index.tsx | 2 +- .../src/app/projects/BoardView/index.tsx | 12 +-- .../src/app/projects/TimelineView/index.tsx | 45 ++++++----- tasker-client/src/app/users/page.tsx | 2 +- tasker-server/seed/populateSeedData.ts | 2 +- tasker-server/src/handlers/createUser.ts | 3 +- tasker-server/src/handlers/getUserTasks.ts | 6 +- 14 files changed, 107 insertions(+), 69 deletions(-) diff --git a/.github/workflows/amplify-deployment.yml b/.github/workflows/amplify-deployment.yml index 8cbdee2..f36b18e 100644 --- a/.github/workflows/amplify-deployment.yml +++ b/.github/workflows/amplify-deployment.yml @@ -58,19 +58,19 @@ jobs: export NEXT_PUBLIC_API_BASE_URL=$(aws ssm get-parameter --name "/tasker/api/base-url" --query "Parameter.Value" --output text) export NEXT_PUBLIC_COGNITO_USER_POOL_ID=$(aws ssm get-parameter --name "/tasker/cognito/user-pool-id" --query "Parameter.Value" --output text) export NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID=$(aws ssm get-parameter --name "/tasker/cognito/client-id" --query "Parameter.Value" --output text) - export S3_PUBLIC_IMAGE_URL=$(aws ssm get-parameter --name "/tasker/s3/public-images-url" --query "Parameter.Value" --output text) + export NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL=$(aws ssm get-parameter --name "/tasker/s3/public-images-url" --query "Parameter.Value" --output text) echo "NEXT_PUBLIC_API_BASE_URL=$NEXT_PUBLIC_API_BASE_URL" >> $GITHUB_ENV echo "NEXT_PUBLIC_COGNITO_USER_POOL_ID=$NEXT_PUBLIC_COGNITO_USER_POOL_ID" >> $GITHUB_ENV echo "NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID=$NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID" >> $GITHUB_ENV - echo "S3_PUBLIC_IMAGE_URL=$S3_PUBLIC_IMAGE_URL" >> $GITHUB_ENV + echo "NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL=$NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL" >> $GITHUB_ENV - name: Set Amplify Environment Variables run: | amplify env set NEXT_PUBLIC_API_BASE_URL=$NEXT_PUBLIC_API_BASE_URL amplify env set NEXT_PUBLIC_COGNITO_USER_POOL_ID=$NEXT_PUBLIC_COGNITO_USER_POOL_ID amplify env set NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID=$NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID - amplify env set S3_PUBLIC_IMAGE_URL=$S3_PUBLIC_IMAGE_URL + amplify env set NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL=$NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL - name: Deploy Amplify App run: | diff --git a/tasker-client/amplify.yml b/tasker-client/amplify.yml index c3a3de9..3145809 100644 --- a/tasker-client/amplify.yml +++ b/tasker-client/amplify.yml @@ -23,4 +23,4 @@ env: NEXT_PUBLIC_API_BASE_URL: "" NEXT_PUBLIC_COGNITO_USER_POOL_ID: "" NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID: "" - S3_PUBLIC_IMAGE_URL: "" + NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL: "" diff --git a/tasker-client/next.config.ts b/tasker-client/next.config.ts index e9ffa30..eede2b9 100644 --- a/tasker-client/next.config.ts +++ b/tasker-client/next.config.ts @@ -1,7 +1,17 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - /* config options here */ + images: { + remotePatterns: [ + { + protocol: "https", + hostname: new URL(process.env.NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL || "") + .hostname, + port: "", + pathname: "/**", + }, + ], + }, }; export default nextConfig; diff --git a/tasker-client/src/app/components/ModalNewTask/index.tsx b/tasker-client/src/app/components/ModalNewTask/index.tsx index 9748383..0631291 100644 --- a/tasker-client/src/app/components/ModalNewTask/index.tsx +++ b/tasker-client/src/app/components/ModalNewTask/index.tsx @@ -1,6 +1,11 @@ import Modal from "@/app/components/Modal"; -import { Priority, Status, useCreateTaskMutation } from "@/state/api"; -import React, { useState } from "react"; +import { + Priority, + Status, + useCreateTaskMutation, + useGetAuthUserQuery, +} from "@/state/api"; +import React, { useEffect, useState } from "react"; import { formatISO } from "date-fns"; type Props = { @@ -22,22 +27,28 @@ const ModalNewTask = ({ isOpen, onClose, id = null }: Props) => { const [assignedUserId, setAssignedUserId] = useState(""); const [projectId, setProjectId] = useState(""); + const { data: currentUser } = useGetAuthUserQuery({}); + const userId = currentUser?.userDetails?.userId ?? null; + + useEffect(() => { + setAuthorUserId(userId || ""); + }, [userId]); + const handleSubmit = async () => { - console.log(title, authorUserId, id, projectId); + if (!(title && authorUserId && (id !== null || projectId))) return; - console.log("Creating task 1.."); - if ( - !(title && authorUserId && assignedUserId && (id !== null || projectId)) - ) - return; - console.log("Creating task 2..."); + const finalAssignedUserId = assignedUserId.trim() || authorUserId; - const formattedStartDate = formatISO(new Date(startDate), { - representation: "complete", - }); - const formattedDueDate = formatISO(new Date(dueDate), { - representation: "complete", - }); + const formattedStartDate = + startDate ?? + formatISO(new Date(startDate), { + representation: "complete", + }); + const formattedDueDate = + dueDate ?? + formatISO(new Date(dueDate), { + representation: "complete", + }); await createTask({ title, @@ -48,16 +59,15 @@ const ModalNewTask = ({ isOpen, onClose, id = null }: Props) => { startDate: formattedStartDate, dueDate: formattedDueDate, authorUserId: authorUserId, - assignedUserId: assignedUserId, + assignedUserId: finalAssignedUserId, projectId: id !== null ? id : projectId, }); + + onClose(); }; const isFormValid = () => { - console.log(title, authorUserId, id, projectId); - return ( - title && authorUserId && assignedUserId && (id !== null || projectId) - ); + return title && authorUserId && (id !== null || projectId); }; const selectStyles = @@ -92,9 +102,13 @@ const ModalNewTask = ({ isOpen, onClose, id = null }: Props) => { setAuthorUserId(e.target.value)} - /> + {authorUserId === "" && ( + setAuthorUserId(e.target.value)} + /> + )} {
{!!currentUserDetails?.profilePictureUrl ? ( {currentUserDetails?.username {
logo {
{!!currentUserDetails?.profilePictureUrl ? ( {currentUserDetails?.username {
{task.attachments && task.attachments.length > 0 && ( {task.attachments[0].fileName} {
{user.profilePictureUrl && ( profile picture { data: fetchedTasks, isLoading, error, + refetch, } = useGetTasksQuery({ projectId }); const [updateTaskStatus] = useUpdateTaskStatusMutation(); const [tasks, setTasks] = useState([]); @@ -43,6 +44,7 @@ const BoardView = ({ projectId, setIsModalNewTaskOpen }: BoardProps) => { try { await updateTaskStatus({ taskId, status: toStatus }); + await refetch(); } catch (error) { console.error("Failed to update task status:", error); setTasks(fetchedTasks || []); @@ -197,7 +199,7 @@ const Task = ({ task }: TaskProps) => { > {task.attachments && task.attachments.length > 0 && ( {task.attachments[0].fileName} {
{task.assignee && ( {task.assignee.username} { )} {task.author && ( {task.author.username} { }); const ganttTasks = useMemo(() => { + if (!tasks || tasks.length === 0) return []; return ( - tasks?.map((task) => ({ - start: new Date(task.startDate as string), - end: new Date(task.dueDate as string), - name: task.title, - id: `Task-${task.taskId}`, - type: "task" as TaskTypeItems, - progress: task.points ? (task.points / 10) * 100 : 0, - isDisabled: false, - })) || [] + tasks + ?.filter((task) => task.startDate && task.dueDate) + .map((task) => ({ + start: new Date(task.startDate as string), + end: new Date(task.dueDate as string), + name: task.title, + id: `Task-${task.taskId}`, + type: "task" as TaskTypeItems, + progress: task.points ? (task.points / 10) * 100 : 0, + isDisabled: false, + })) || [] ); }, [tasks]); @@ -66,16 +69,20 @@ const Timeline = ({ projectId, setIsModalNewTaskOpen }: Props) => {
-
- -
+ {ganttTasks.length > 0 && ( +
+ +
+ )}