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.
feat: checklist in weekly planning with inbox zero, and upload financ…
…ial data and projects
- Loading branch information
Carsten Koch
committed
Nov 23, 2024
1 parent
7e5397a
commit bb99960
Showing
8 changed files
with
190 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { type Schema } from "@/amplify/data/resource"; | ||
import { generateClient, SelectionSet } from "aws-amplify/data"; | ||
import { differenceInCalendarDays } from "date-fns"; | ||
import { first, flow, get, identity } from "lodash/fp"; | ||
import useSWR from "swr"; | ||
import { handleApiErrors } from "./globals"; | ||
const client = generateClient<Schema>(); | ||
|
||
const selectionSet = ["createdAt"] as const; | ||
|
||
type MrrLatestUploadData = SelectionSet< | ||
Schema["MrrDataUpload"]["type"], | ||
typeof selectionSet | ||
>; | ||
|
||
type SfdcLatestUploadData = SelectionSet< | ||
Schema["CrmProjectImport"]["type"], | ||
typeof selectionSet | ||
>; | ||
|
||
const isTooOld = (dateStr: string | undefined) => | ||
!dateStr || differenceInCalendarDays(new Date(), dateStr) >= 7; | ||
|
||
const fetchSfdcLatestUpload = async () => { | ||
const { data, errors } = | ||
await client.models.CrmProjectImport.listByImportStatus( | ||
{ | ||
status: "DONE", | ||
}, | ||
{ | ||
sortDirection: "DESC", | ||
limit: 1, | ||
selectionSet, | ||
} | ||
); | ||
if (errors) { | ||
handleApiErrors(errors, "Loading SfdcLatestUpload failed"); | ||
throw errors; | ||
} | ||
try { | ||
return flow( | ||
identity<SfdcLatestUploadData[] | undefined>, | ||
first, | ||
get("createdAt"), | ||
isTooOld | ||
)(data); | ||
} catch (error) { | ||
console.error("fetchSfdcLatestUpload", error); | ||
throw error; | ||
} | ||
}; | ||
|
||
const fetchMrrLatestUpload = async () => { | ||
const { data, errors } = | ||
await client.models.MrrDataUpload.listMrrDataUploadByStatusAndCreatedAt( | ||
{ status: "DONE" }, | ||
{ sortDirection: "DESC", limit: 1, selectionSet } | ||
); | ||
if (errors) { | ||
handleApiErrors(errors, "Loading MrrLatestUpload failed"); | ||
throw errors; | ||
} | ||
try { | ||
return flow( | ||
identity<MrrLatestUploadData[] | undefined>, | ||
first, | ||
get("createdAt"), | ||
isTooOld | ||
)(data); | ||
} catch (error) { | ||
console.error("fetchMrrLatestUpload", error); | ||
throw error; | ||
} | ||
}; | ||
|
||
const useLatestUploadsWork = () => { | ||
const { data: mrrUploadTooOld, mutate: mutateMrr } = useSWR( | ||
"/api/mrr-latest", | ||
fetchMrrLatestUpload | ||
); | ||
|
||
const { data: sfdcUploadTooOld, mutate: mutateSfdc } = useSWR( | ||
"/api/sfdc-latest", | ||
fetchSfdcLatestUpload | ||
); | ||
|
||
return { mrrUploadTooOld, mutateMrr, sfdcUploadTooOld, mutateSfdc }; | ||
}; | ||
|
||
export default useLatestUploadsWork; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { FC } from "react"; | ||
|
||
type PlanWeekActionProps = { | ||
label: string; | ||
}; | ||
|
||
const PlanWeekAction: FC<PlanWeekActionProps> = ({ label }) => ( | ||
<div className="border-2 border-[--context-color] rounded-md flex justify-center p-1 font-semibold"> | ||
Next Action: {label} | ||
</div> | ||
); | ||
|
||
export default PlanWeekAction; |
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