-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
766 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
prisma/migrations/20240216145819_add_author_for_task/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
Warnings: | ||
- Added the required column `reporterId` to the `tasks` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `updatedAt` to the `tasks` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- DropForeignKey | ||
ALTER TABLE "collaborators" DROP CONSTRAINT "collaborators_projectId_fkey"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "tasks" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
ADD COLUMN "reporterId" INTEGER NOT NULL, | ||
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "collaborators" ADD CONSTRAINT "collaborators_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "projects"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "tasks" ADD CONSTRAINT "tasks_reporterId_fkey" FOREIGN KEY ("reporterId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/app/users/[username]/projects/[projectName]/(task)/AssigneeAutocomplete.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { AsyncAutocomplete } from '@/components/form'; | ||
import { useSession } from 'next-auth/react'; | ||
import Link from 'next/link'; | ||
import { useEffect, useState } from 'react'; | ||
import { Control } from 'react-hook-form'; | ||
|
||
interface AssigneeAutocompleteProps { | ||
projectId: number; | ||
name: string; | ||
control: Control<any>; | ||
label?: string; | ||
} | ||
|
||
interface Assignee { | ||
id: number; | ||
username: string; | ||
name: string; | ||
} | ||
|
||
export function AssigneeAutocomplete({ | ||
projectId, | ||
name, | ||
control, | ||
label, | ||
}: AssigneeAutocompleteProps) { | ||
const session = useSession(); | ||
const [assigneeOptions, setAssigneeOptions] = useState<Assignee[]>([ | ||
session.data!.user, | ||
]); | ||
|
||
const fetchAssignees = (username?: string) => { | ||
const searchParams = new URLSearchParams(); | ||
if (username?.length) { | ||
searchParams.set('username', username); | ||
} | ||
const currentUser = session.data!.user; | ||
fetch( | ||
`${ | ||
window.location.origin | ||
}/api/projects/${projectId}/collaborators?${searchParams.toString()}` | ||
) | ||
.then((res) => res.json()) | ||
.then((result) => | ||
setAssigneeOptions( | ||
[currentUser].concat(...(Array.isArray(result) ? result : [])) | ||
) | ||
); | ||
}; | ||
|
||
useEffect(() => { | ||
fetchAssignees(); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
return ( | ||
<AsyncAutocomplete | ||
name={name} | ||
control={control} | ||
options={assigneeOptions} | ||
onSearch={fetchAssignees} | ||
getOptionValue={(option) => ({ | ||
id: option.id, | ||
username: option.username, | ||
})} | ||
getSearchValue={(option) => option.username} | ||
renderOption={(option) => ( | ||
<div className='p-2 flex items-center gap-2 hover:bg-gray-100 cursor-pointer rounded-sm'> | ||
<b className='font-semibold'>{option.username}</b> | ||
<span className='text-gray-500'>{option.name}</span> | ||
</div> | ||
)} | ||
renderValue={(value) => ( | ||
<Link href={`/users/${value.username}`}>{value.username}</Link> | ||
)} | ||
optionKey='username' | ||
valueKey='username' | ||
label={label} | ||
placeholder='Select assignee' | ||
autocompletePlaceholder='Search by username' | ||
noResultPlaceholder='No assignees found' | ||
/> | ||
); | ||
} |
Oops, something went wrong.