Skip to content

Commit

Permalink
Merge pull request #63 from cabcookie/staging
Browse files Browse the repository at this point in the history
Inbox einführen
  • Loading branch information
cabcookie authored May 21, 2024
2 parents d4b2ac9 + 4771240 commit f425644
Show file tree
Hide file tree
Showing 59 changed files with 8,096 additions and 5,287 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
components/import-data
45 changes: 43 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": [
"next/core-web-vitals",
"plugin:storybook/recommended"
]
"plugin:storybook/recommended",
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": ["react", "@typescript-eslint", "prettier"],
"overrides": [
{
"files": ["**/*.ts", "**/*.tsx"],
"rules": {
"@typescript-eslint/no-unused-vars": [
"error",
{
"varsIgnorePattern": "^_",
"argsIgnorePattern": "^_"
}
]
}
}
],
"rules": {
"prettier/prettier": [
"error",
{
"singleQuote": false
}
],
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off"
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ next-env.d.ts
# amplify
.amplify
amplifyconfiguration*
amplify_outputs.json
components/import-data/*
!components/import-data/imports-aws-sdk

Expand Down
21 changes: 21 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"printWidth": 80,
"trailingComma": "es5",
"overrides": [
{
"files": "*.ts",
"options": {
"parser": "typescript"
}
},
{
"files": "*.tsx",
"options": {
"parser": "typescript"
}
}
]
}
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"davidanson.vscode-markdownlint"
]
}
30 changes: 30 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"eslint.format.enable": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "always",
"source.organizeImports": "always",
"source.fixAll.markdownlint": "explicit"
},
"typescript.validate.enable": true,
"typescript.format.enable": true,
"typescript.format.insertSpaceAfterCommaDelimiter": true,
"typescript.format.insertSpaceAfterConstructor": false,
"typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": true,
"typescript.format.insertSpaceAfterKeywordsInControlFlowStatements": true,
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": true,
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true,
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
"typescript.format.insertSpaceAfterSemicolonInForStatements": true,
"typescript.format.insertSpaceBeforeAndAfterBinaryOperators": true,
"typescript.format.insertSpaceBeforeFunctionParenthesis": false,
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": false,
"typescript.format.placeOpenBraceOnNewLineForFunctions": false,
"typescript.preferences.quoteStyle": "double",
"[markdown]": {
"editor.formatOnSave": true,
"editor.formatOnPaste": true
}
}
2 changes: 1 addition & 1 deletion amplify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ backend:
commands:
- nvm use 18
- npm ci
- npx amplify pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID
- npx ampx pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID
frontend:
phases:
preBuild:
Expand Down
18 changes: 14 additions & 4 deletions amplify/data/resource.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ClientSchema, a, defineData } from "@aws-amplify/backend";
import { a, defineData, type ClientSchema } from "@aws-amplify/backend";

const schema = a.schema({
Context: a.enum(["family", "hobby", "work"]),
Expand All @@ -15,10 +15,13 @@ const schema = a.schema({
owner: a
.string()
.authorization((allow) => [allow.owner().to(["read", "delete"])]),
note: a.string().required(),
done: a.id().required(),
note: a.string(),
formatVersion: a.integer().default(1),
noteJson: a.json(),
status: a.id().required(),
movedToActivityId: a.string(),
})
.secondaryIndexes((inbox) => [inbox("done")])
.secondaryIndexes((inbox) => [inbox("status")])
.authorization((allow) => [allow.owner()]),
DayPlan: a
.model({
Expand Down Expand Up @@ -92,6 +95,8 @@ const schema = a.schema({
.authorization((allow) => [allow.owner().to(["read", "delete"])]),
notionId: a.integer(),
notes: a.string(),
formatVersion: a.integer().default(1),
notesJson: a.json(),
forProjects: a.hasMany("ProjectActivity", "activityId"),
meetingActivitiesId: a.id(),
forMeeting: a.belongsTo("Meeting", "meetingActivitiesId"),
Expand Down Expand Up @@ -166,6 +171,8 @@ const schema = a.schema({
name: a.string().required(),
order: a.integer(),
introduction: a.string(),
introductionJson: a.json(),
formatVersion: a.integer().default(1),
subsidiaries: a.hasMany("Account", "accountSubsidiariesId"),
projects: a.hasMany("AccountProjects", "accountId"),
accountSubsidiariesId: a.id(),
Expand Down Expand Up @@ -260,6 +267,9 @@ const schema = a.schema({
onHoldTill: a.date(),
myNextActions: a.string(),
othersNextActions: a.string(),
formatVersion: a.integer().default(1),
myNextActionsJson: a.json(),
othersNextActionsJson: a.json(),
context: a.ref("Context").required(),
accounts: a.hasMany("AccountProjects", "projectsId"),
batches: a.hasMany("SixWeekBatchProjects", "projectsId"),
Expand Down
78 changes: 57 additions & 21 deletions api/ContextAccounts.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
import { FC, ReactNode, createContext, useContext } from "react";
import { type Schema } from "@/amplify/data/resource";
import {
EditorJsonContent,
transformNotesVersion,
} from "@/components/ui-elements/notes-writer/NotesWriter";
import { SelectionSet, generateClient } from "aws-amplify/data";
import { FC, ReactNode, createContext, useContext } from "react";
import useSWR from "swr";
import { handleApiErrors } from "./globals";
const client = generateClient<Schema>();

type UpdateAccountProps = {
id: string;
name?: string;
introduction?: EditorJsonContent;
};

interface AccountsContextType {
accounts: Account[] | undefined;
errorAccounts: any;
loadingAccounts: boolean;
createAccount: (
accountName: string
) => Promise<Schema["Account"] | undefined>;
) => Promise<Schema["Account"]["type"] | undefined>;
getAccountById: (accountId: string) => Account | undefined;
saveAccountName: (
accountId: string,
accountName: string
) => Promise<string | undefined>;
updateAccount: (props: UpdateAccountProps) => Promise<string | undefined>;
}

export type Account = {
id: string;
name: string;
introduction: string;
introduction?: EditorJsonContent | string;
controllerId?: string;
order: number;
responsibilities: { startDate: Date; endDate?: Date }[];
Expand All @@ -33,24 +40,32 @@ const selectionSet = [
"name",
"accountSubsidiariesId",
"introduction",
"introductionJson",
"formatVersion",
"order",
"responsibilities.startDate",
"responsibilities.endDate",
] as const;

type AccountData = SelectionSet<Schema["Account"], typeof selectionSet>;
type AccountData = SelectionSet<Schema["Account"]["type"], typeof selectionSet>;

export const mapAccount: (account: AccountData) => Account = ({
id,
name,
accountSubsidiariesId,
introduction,
introductionJson,
formatVersion,
order,
responsibilities,
}) => ({
id,
name,
introduction: introduction || "",
introduction: transformNotesVersion({
version: formatVersion,
notes: introduction,
notesJson: introductionJson,
}),
controllerId: accountSubsidiariesId || undefined,
order: order || 0,
responsibilities: responsibilities
Expand Down Expand Up @@ -86,13 +101,12 @@ export const AccountsContextProvider: FC<AccountsContextProviderProps> = ({

const createAccount = async (
accountName: string
): Promise<Schema["Account"] | undefined> => {
): Promise<Schema["Account"]["type"] | undefined> => {
if (accountName.length < 3) return;

const newAccount: Account = {
id: crypto.randomUUID(),
name: accountName,
introduction: "",
order: 0,
responsibilities: [],
};
Expand All @@ -102,25 +116,47 @@ export const AccountsContextProvider: FC<AccountsContextProviderProps> = ({

const { data, errors } = await client.models.Account.create({
name: accountName,
formatVersion: 2,
});
if (errors) handleApiErrors(errors, "Error creating account");
mutate(updatedAccounts);
return data;
return data || undefined;
};

const getAccountById = (accountId: string) =>
accounts?.find((account) => account.id === accountId);

const saveAccountName = async (accountId: string, accountName: string) => {
const updateAccount = async ({
id,
name,
introduction,
}: UpdateAccountProps) => {
const updAccount: Account | undefined = accounts?.find((a) => a.id === id);
if (!updAccount) return;

Object.assign(updAccount, {
...(name && { name }),
...(introduction && { introduction }),
});

const updated: Account[] =
accounts?.map((a) =>
a.id !== accountId ? a : { ...a, name: accountName }
) || [];
accounts?.map((a) => (a.id === id ? updAccount : a)) || [];
mutate(updated, false);
const { data, errors } = await client.models.Account.update({
id: accountId,
name: accountName,
});

const newAccount = {
id,
name,
...(introduction
? {
introductionJson: JSON.stringify(introduction),
formatVersion: 2,
introduction: null,
}
: {}),
};

const { data, errors } = await client.models.Account.update(newAccount);

if (errors) handleApiErrors(errors, "Error updating account");
mutate(updated);
return data?.id;
Expand All @@ -134,7 +170,7 @@ export const AccountsContextProvider: FC<AccountsContextProviderProps> = ({
loadingAccounts,
createAccount,
getAccountById,
saveAccountName,
updateAccount,
}}
>
{children}
Expand Down
Loading

0 comments on commit f425644

Please sign in to comment.