-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add file edit options on frontend #164
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -105,7 +105,11 @@ model File { | |||
id String @id @default(auto()) @map("_id") @db.ObjectId | |||
date DateTime // will zero out the hours | |||
filetype String | |||
|
|||
// Use with Google API | |||
fileId String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it easier to keep track instead of parsing the string.
@@ -106,13 +106,14 @@ export const PATCH = withSessionAndRole( | |||
); | |||
const studentIDsToAdd = seniorBody.StudentIDs; | |||
|
|||
const { StudentIDs: _, ...other } = seniorBody; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually was a bug we didn't notice before. Without destructuring StudentIDs
, the relation on User
side is not updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, nickbar!
}, | ||
include: { senior: true }, | ||
}); | ||
const otherFiles = await prisma.file.findMany({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this check, user can make files with the same date!
!user.SeniorIDs.some( | ||
(seniorId: string) => seniorId === fileData.seniorId | ||
) || | ||
otherFiles.length > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same problem here!
}: { | ||
seniorId: string; | ||
seniorFolder: string; | ||
files: PrismaFile[]; | ||
editFile?: PrismaFile; | ||
setEditFile: React.Dispatch<React.SetStateAction<PrismaFile | undefined>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is too clean, but it makes the most sense given the time constraint.
|
||
if ( | ||
!user.SeniorIDs.some((seniorId: string) => seniorId === fileData.seniorId) | ||
otherFiles.length > 0 || | ||
maybeFile == null || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use triple equals ===
}, | ||
}); | ||
onClick={async () => { | ||
editFile == null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
===
const fetching = fetchingCreateFile || fetchingUpdateFile; | ||
|
||
React.useEffect(() => { | ||
if (editFile != undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!==
@@ -168,19 +200,28 @@ const AddFile = ({ | |||
selectedTags.length == 0 || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this wasn't one of your changes but triple equals ===
}} | ||
> | ||
{!fetching ? "Create" : "Loading..."} | ||
{fetching ? "Loading..." : editFile == null ? "Create" : "Update"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
===
}); | ||
|
||
const fetching = fetchingDeleteFile; | ||
const editable = setFileEdit != undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!==
}) => { | ||
const [showAddFilePopUp, setShowAddFilePopUp] = useState<boolean>(false); | ||
|
||
const handlePopUp = () => { | ||
setShowAddFilePopUp(!showAddFilePopUp); | ||
}; | ||
|
||
React.useEffect(() => { | ||
if (editFile != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!==
}, | ||
}); | ||
|
||
if (file === null) { | ||
if (file == null || !file.senior.StudentIDs.includes(session.user.id)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
===
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work Nick! Changes requested for the error codes and maybe a later ticket for user feed back
@@ -106,13 +106,14 @@ export const PATCH = withSessionAndRole( | |||
); | |||
const studentIDsToAdd = seniorBody.StudentIDs; | |||
|
|||
const { StudentIDs: _, ...other } = seniorBody; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, nickbar!
src/app/api/file/[fileId]/route.ts
Outdated
FileResponse.parse({ | ||
code: "INVALID_REQUEST", | ||
message: "Not a valid request", | ||
code: "SUCCESS_UPDATE", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think unsuccessful error code to display on front end for some user feedback is more smooth
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Query logic works great. Great changes, should be good to merge!
65f9a7e
to
ba2876b
Compare
Resolved with @wkim10 on |
Description