forked from aws-samples/amplify-next-template
-
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.
Merge pull request #71 from cabcookie/staging
Inbox Workflow optimieren und Editieren verlässlicher machen
- Loading branch information
Showing
21 changed files
with
609 additions
and
461 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { type Schema } from "@/amplify/data/resource"; | ||
import { EditorJsonContent } from "@/components/ui-elements/notes-writer/NotesWriter"; | ||
import { generateClient } from "aws-amplify/data"; | ||
import useSWR from "swr"; | ||
import { handleApiErrors } from "./globals"; | ||
import { InboxStatus, mapInbox } from "./useInbox"; | ||
const client = generateClient<Schema>(); | ||
|
||
const fetchInboxItem = (itemId?: string) => async () => { | ||
if (!itemId) return; | ||
const { data, errors } = await client.models.Inbox.get({ id: itemId }); | ||
if (errors) throw errors; | ||
if (!data) throw new Error("fetchInboxItem didn't retrieve data"); | ||
return mapInbox(data); | ||
}; | ||
|
||
const useInboxItem = (itemId?: string) => { | ||
const { | ||
data: inboxItem, | ||
error: errorInboxItem, | ||
isLoading: loadingInboxItem, | ||
mutate, | ||
} = useSWR(`/api/inbox/${itemId}`, fetchInboxItem(itemId)); | ||
|
||
const updateNote = async (id: string, note: EditorJsonContent) => { | ||
const { data, errors } = await client.models.Inbox.update({ | ||
id, | ||
note: null, | ||
formatVersion: 2, | ||
noteJson: JSON.stringify(note), | ||
}); | ||
if (errors) handleApiErrors(errors, "Error updating inbox item"); | ||
if (!data) return; | ||
const updated = mapInbox(data); | ||
mutate(updated); | ||
return data.id; | ||
}; | ||
|
||
const moveInboxItemToProject = async (projectId: string) => { | ||
if (!inboxItem) return; | ||
|
||
const { data: activity, errors: activityErrors } = | ||
await client.models.Activity.create({ | ||
finishedOn: inboxItem.createdAt.toISOString(), | ||
formatVersion: 2, | ||
notes: null, | ||
notesJson: JSON.stringify(inboxItem.note), | ||
}); | ||
if (activityErrors) | ||
return handleApiErrors( | ||
activityErrors, | ||
"Error creating activity with inbox notes" | ||
); | ||
if (!activity) return; | ||
|
||
const { errors: projectActivityErrors } = | ||
await client.models.ProjectActivity.create({ | ||
activityId: activity.id, | ||
projectsId: projectId, | ||
}); | ||
if (projectActivityErrors) | ||
return handleApiErrors( | ||
projectActivityErrors, | ||
"Error linking activity with project" | ||
); | ||
|
||
const { data, errors } = await client.models.Inbox.update({ | ||
id: inboxItem.id, | ||
status: "done", | ||
movedToActivityId: activity.id, | ||
}); | ||
|
||
if (errors) | ||
return handleApiErrors(errors, "Error updating status of inbox item"); | ||
return data?.id; | ||
}; | ||
|
||
const updateStatus = async (id: string, status: InboxStatus) => { | ||
if (inboxItem) mutate({ ...inboxItem, status }, false); | ||
const { data, errors } = await client.models.Inbox.update({ id, status }); | ||
if (errors) handleApiErrors(errors, "Can't update status"); | ||
if (!data) return; | ||
mutate(mapInbox(data)); | ||
return data.id; | ||
}; | ||
|
||
return { | ||
inboxItem, | ||
errorInboxItem, | ||
loadingInboxItem, | ||
updateNote, | ||
moveInboxItemToProject, | ||
updateStatus, | ||
}; | ||
}; | ||
|
||
export default useInboxItem; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { FC, useState } from "react"; | ||
import SubmitButton from "../ui-elements/buttons/submit-button"; | ||
import ProjectDetails from "../ui-elements/project-details/project-details"; | ||
import ProjectSelector from "../ui-elements/project-selector"; | ||
import ProjectName from "../ui-elements/tokens/project-name"; | ||
import styles from "./Inbox.module.css"; | ||
import { WorkflowStepComponentProps } from "./workflow"; | ||
|
||
const ClarifyAction: FC<WorkflowStepComponentProps> = ({ | ||
responses, | ||
action, | ||
}) => { | ||
const [selectedProject, setSelectedProject] = useState<string | null>(null); | ||
|
||
const respondProjectSelected = async (projectId: string | null) => { | ||
if (!projectId) return; | ||
if (!responses) return; | ||
if (responses.length !== 1 && responses[0].response !== "next") return; | ||
await action(responses[0], projectId); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<ProjectSelector | ||
placeholder="Select project…" | ||
onChange={setSelectedProject} | ||
allowCreateProjects | ||
/> | ||
{selectedProject && ( | ||
<div> | ||
<ProjectName projectId={selectedProject} /> | ||
<ProjectDetails projectId={selectedProject} /> | ||
<SubmitButton onClick={() => respondProjectSelected(selectedProject)}> | ||
Confirm Changes | ||
</SubmitButton> | ||
</div> | ||
)} | ||
<div className={styles.spacer}> | ||
<strong>Inbox Notes (will be moved to selected project):</strong> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ClarifyAction; |
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,36 @@ | ||
.spacer { | ||
margin-top: 3rem; | ||
} | ||
|
||
.question { | ||
font-size: var(--font-size-x-large); | ||
display: flex; | ||
flex-direction: row; | ||
vertical-align: middle; | ||
font-weight: bold; | ||
color: var(--color-btn); | ||
margin-top: -0.6rem; | ||
gap: 1rem; | ||
} | ||
|
||
.decisionBtns { | ||
font-weight: normal; | ||
font-size: var(--font-size-large); | ||
display: flex; | ||
flex-direction: row; | ||
vertical-align: middle; | ||
margin-top: -0.4rem; | ||
gap: 0.4rem; | ||
} | ||
|
||
.positive { | ||
background-color: var(--secondary-button-bg-color); | ||
} | ||
|
||
.negative { | ||
background-color: var(--primary-button-bg-color); | ||
} | ||
|
||
.small { | ||
font-size: var(--font-size-small); | ||
} |
Oops, something went wrong.