From 5c779f64bbd26267081033f9193bded4086b7d51 Mon Sep 17 00:00:00 2001 From: Steve Laing Date: Tue, 2 Jan 2024 16:17:29 +0000 Subject: [PATCH 01/21] Remove ka-table and add form related deps --- package-lock.json | 170 +++++++++++++++++++++++++++++++++++++++++++--- package.json | 6 +- 2 files changed, 164 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index 48e69e8..5dccfce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,13 +14,15 @@ "autoprefixer": "10.4.15", "eslint": "8.49.0", "eslint-config-next": "13.4.19", - "ka-table": "8.3.2", "next": "13.4.19", "postcss": "8.4.29", "react": "18.2.0", "react-dom": "18.2.0", + "react-query": "3.39.3", + "swr": "2.2.4", "tailwindcss": "3.3.3", - "typescript": "5.2.2" + "typescript": "5.2.2", + "yup": "1.3.2" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -800,6 +802,14 @@ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, + "node_modules/big-integer": { + "version": "1.6.51", + "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.51.tgz", + "integrity": "sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg==", + "engines": { + "node": ">=0.6" + } + }, "node_modules/binary-extensions": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", @@ -828,6 +838,21 @@ "node": ">=8" } }, + "node_modules/broadcast-channel": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/broadcast-channel/-/broadcast-channel-3.7.0.tgz", + "integrity": "sha512-cIAKJXAxGJceNZGTZSBzMxzyOn72cVgPnKx4dc6LRjQgbaJUQqhy5rzL3zbMxkMWsGKkv2hSFkPRMEXfoMZ2Mg==", + "dependencies": { + "@babel/runtime": "^7.7.2", + "detect-node": "^2.1.0", + "js-sha3": "0.8.0", + "microseconds": "0.2.0", + "nano-time": "1.0.0", + "oblivious-set": "1.0.0", + "rimraf": "3.0.2", + "unload": "2.2.0" + } + }, "node_modules/browserslist": { "version": "4.21.10", "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.21.10.tgz", @@ -1095,6 +1120,11 @@ "node": ">=6" } }, + "node_modules/detect-node": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/detect-node/-/detect-node-2.1.0.tgz", + "integrity": "sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==" + }, "node_modules/didyoumean": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/didyoumean/-/didyoumean-1.2.2.tgz", @@ -2448,6 +2478,11 @@ "jiti": "bin/jiti.js" } }, + "node_modules/js-sha3": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz", + "integrity": "sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q==" + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -2504,14 +2539,6 @@ "node": ">=4.0" } }, - "node_modules/ka-table": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/ka-table/-/ka-table-8.3.2.tgz", - "integrity": "sha512-b08of5T1Kpna4Ahnx7BKPmlY5pOuAb516ESqDmNi4oIdnQH5okid5Ah5VswjCCSDXlFYaYrfuN07mm9LdpVcCg==", - "peerDependencies": { - "react": "^16.8.3 || ^17.0.0-0 || ^18.0.0-0" - } - }, "node_modules/keyv": { "version": "4.5.3", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.3.tgz", @@ -2599,6 +2626,15 @@ "node": ">=10" } }, + "node_modules/match-sorter": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/match-sorter/-/match-sorter-6.3.1.tgz", + "integrity": "sha512-mxybbo3pPNuA+ZuCUhm5bwNkXrJTbsk5VWbR5wiwz/GC6LIiegBGn2w3O08UG/jdbYLinw51fSQ5xNU1U3MgBw==", + "dependencies": { + "@babel/runtime": "^7.12.5", + "remove-accents": "0.4.2" + } + }, "node_modules/merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -2619,6 +2655,11 @@ "node": ">=8.6" } }, + "node_modules/microseconds": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/microseconds/-/microseconds-0.2.0.tgz", + "integrity": "sha512-n7DHHMjR1avBbSpsTBj6fmMGh2AGrifVV4e+WYc3Q9lO+xnSZ3NyhcBND3vzzatt05LFhoKFRxrIyklmLlUtyA==" + }, "node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -2653,6 +2694,14 @@ "thenify-all": "^1.0.0" } }, + "node_modules/nano-time": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/nano-time/-/nano-time-1.0.0.tgz", + "integrity": "sha512-flnngywOoQ0lLQOTRNexn2gGSNuM9bKj9RZAWSzhQ+UJYaAFG9bac4DW9VHjUAzrOaIcajHybCTHe/bkvozQqA==", + "dependencies": { + "big-integer": "^1.6.16" + } + }, "node_modules/nanoid": { "version": "3.3.6", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", @@ -2882,6 +2931,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/oblivious-set": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/oblivious-set/-/oblivious-set-1.0.0.tgz", + "integrity": "sha512-z+pI07qxo4c2CulUHCDf9lcqDlMSo72N/4rLUpRXf6fu+q8vjt8y0xS+Tlf8NTJDdTXHbdeO1n3MlbctwEoXZw==" + }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -3156,6 +3210,11 @@ "react-is": "^16.13.1" } }, + "node_modules/property-expr": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/property-expr/-/property-expr-2.0.6.tgz", + "integrity": "sha512-SVtmxhRE/CGkn3eZY1T6pC8Nln6Fr/lu1mKSgRud0eC73whjGfoAogbn78LkD8aFL0zz3bAFerKSnOl7NlErBA==" + }, "node_modules/punycode": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", @@ -3211,6 +3270,31 @@ "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" }, + "node_modules/react-query": { + "version": "3.39.3", + "resolved": "https://registry.npmjs.org/react-query/-/react-query-3.39.3.tgz", + "integrity": "sha512-nLfLz7GiohKTJDuT4us4X3h/8unOh+00MLb2yJoGTPjxKs2bc1iDhkNx2bd5MKklXnOD3NrVZ+J2UXujA5In4g==", + "dependencies": { + "@babel/runtime": "^7.5.5", + "broadcast-channel": "^3.4.1", + "match-sorter": "^6.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0" + }, + "peerDependenciesMeta": { + "react-dom": { + "optional": true + }, + "react-native": { + "optional": true + } + } + }, "node_modules/read-cache": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.0.tgz", @@ -3270,6 +3354,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/remove-accents": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/remove-accents/-/remove-accents-0.4.2.tgz", + "integrity": "sha512-7pXIJqJOq5tFgG1A2Zxti3Ht8jJF337m4sowbuHsW30ZnkQFnDzy9qBNhgzX8ZLW4+UBcXiiR7SwR6pokHsxiA==" + }, "node_modules/resolve": { "version": "1.22.4", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.4.tgz", @@ -3643,6 +3732,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/swr": { + "version": "2.2.4", + "resolved": "https://registry.npmjs.org/swr/-/swr-2.2.4.tgz", + "integrity": "sha512-njiZ/4RiIhoOlAaLYDqwz5qH/KZXVilRLvomrx83HjzCWTfa+InyfAjv05PSFxnmLzZkNO9ZfvgoqzAaEI4sGQ==", + "dependencies": { + "client-only": "^0.0.1", + "use-sync-external-store": "^1.2.0" + }, + "peerDependencies": { + "react": "^16.11.0 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/tailwindcss": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.3.3.tgz", @@ -3711,6 +3812,11 @@ "node": ">=0.8" } }, + "node_modules/tiny-case": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tiny-case/-/tiny-case-1.0.3.tgz", + "integrity": "sha512-Eet/eeMhkO6TX8mnUteS9zgPbUMQa4I6Kkp5ORiBD5476/m+PIRiumP5tmh5ioJpH7k51Kehawy2UDfsnxxY8Q==" + }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -3722,6 +3828,11 @@ "node": ">=8.0" } }, + "node_modules/toposort": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/toposort/-/toposort-2.0.2.tgz", + "integrity": "sha512-0a5EOkAUp8D4moMi2W8ZF8jcga7BgZd91O/yabJCFY8az+XSzeGyTKs0Aoo897iV1Nj6guFq8orWDS96z91oGg==" + }, "node_modules/ts-api-utils": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.0.3.tgz", @@ -3863,6 +3974,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/unload": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/unload/-/unload-2.2.0.tgz", + "integrity": "sha512-B60uB5TNBLtN6/LsgAf3udH9saB5p7gqJwcFfbOEZ8BcBHnGwCf6G/TGiEqkRAxX7zAFIUtzdrXQSdL3Q/wqNA==", + "dependencies": { + "@babel/runtime": "^7.6.2", + "detect-node": "^2.0.4" + } + }, "node_modules/update-browserslist-db": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.11.tgz", @@ -3900,6 +4020,14 @@ "punycode": "^2.1.0" } }, + "node_modules/use-sync-external-store": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz", + "integrity": "sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==", + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", @@ -4032,6 +4160,28 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/yup": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/yup/-/yup-1.3.2.tgz", + "integrity": "sha512-6KCM971iQtJ+/KUaHdrhVr2LDkfhBtFPRnsG1P8F4q3uUVQ2RfEM9xekpha9aA4GXWJevjM10eDcPQ1FfWlmaQ==", + "dependencies": { + "property-expr": "^2.0.5", + "tiny-case": "^1.0.3", + "toposort": "^2.0.2", + "type-fest": "^2.19.0" + } + }, + "node_modules/yup/node_modules/type-fest": { + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz", + "integrity": "sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==", + "engines": { + "node": ">=12.20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/zod": { "version": "3.21.4", "resolved": "https://registry.npmjs.org/zod/-/zod-3.21.4.tgz", diff --git a/package.json b/package.json index 3a6668e..927191a 100644 --- a/package.json +++ b/package.json @@ -15,12 +15,14 @@ "autoprefixer": "10.4.15", "eslint": "8.49.0", "eslint-config-next": "13.4.19", - "ka-table": "8.3.2", "next": "13.4.19", "postcss": "8.4.29", "react": "18.2.0", "react-dom": "18.2.0", + "react-query": "3.39.3", + "swr": "2.2.4", "tailwindcss": "3.3.3", - "typescript": "5.2.2" + "typescript": "5.2.2", + "yup": "1.3.2" } } From 3eed749b27a5008167b9301af5064bfc205cb3c5 Mon Sep 17 00:00:00 2001 From: Steve Laing Date: Tue, 2 Jan 2024 16:19:03 +0000 Subject: [PATCH 02/21] Remove local storage lib --- app/lib/useLocalStorage.tsx | 42 ------------------------------------- 1 file changed, 42 deletions(-) delete mode 100644 app/lib/useLocalStorage.tsx diff --git a/app/lib/useLocalStorage.tsx b/app/lib/useLocalStorage.tsx deleted file mode 100644 index 74638df..0000000 --- a/app/lib/useLocalStorage.tsx +++ /dev/null @@ -1,42 +0,0 @@ -// credits to https://usehooks.com/useLocalStorage/ - -import { dequal as deepEqual } from 'dequal' -import { useCallback, useState } from 'react' - -export function useLocalStorage(key: string, initialValue: T): [T, (value: T) => void] { - // State to store our value - // Pass initial state function to useState so logic is only executed once - const [storedValue, setStoredValue] = useState(() => { - try { - // Get from local storage by key - const item = window.localStorage.getItem(key) - // Parse stored json or if none return initialValue - return item ? JSON.parse(item) : initialValue - } catch (error) { - // If error also return initialValue - console.log(error) - return initialValue - } - }) - - // Return a wrapped version of useState's setter function that ... - // ... persists the new value to localStorage. - const setValue = useCallback( - (value: T) => { - try { - if (!deepEqual(storedValue, value)) { - // Save state - setStoredValue(value) - // Save to local storage - window.localStorage.setItem(key, JSON.stringify(value)) - } - } catch (error) { - // A more advanced implementation would handle the error case - console.log(error) - } - }, - [key, storedValue] - ) - - return [storedValue, setValue] -} From 307ea9b69ceaf6ee7686315fc391be2bf58cf758 Mon Sep 17 00:00:00 2001 From: Steve Laing Date: Tue, 2 Jan 2024 16:19:44 +0000 Subject: [PATCH 03/21] Remove ka table and title components --- app/components/suspense-table.tsx | 167 ------------------------------ app/components/title.tsx | 16 --- 2 files changed, 183 deletions(-) delete mode 100644 app/components/suspense-table.tsx delete mode 100644 app/components/title.tsx diff --git a/app/components/suspense-table.tsx b/app/components/suspense-table.tsx deleted file mode 100644 index 1275b0f..0000000 --- a/app/components/suspense-table.tsx +++ /dev/null @@ -1,167 +0,0 @@ -'use client' - -import "ka-table/style.css"; - -import React, { useState } from 'react'; - -import { ITableProps, kaReducer, Table } from 'ka-table'; -import { ICellEditorProps, ICellTextProps, IHeadCellProps } from 'ka-table/props'; -import { deleteRow, hideNewRow, saveNewRow, showNewRow } from 'ka-table/actionCreators'; -import { DataType, EditingMode, SortingMode } from 'ka-table/enums'; -import { DispatchFunc } from 'ka-table/types'; - -import { useLocalStorage } from './../lib/useLocalStorage'; - -const LOCAL_STORAGE_KEY = 'SuspenseTableData'; - -const blankRow = { - profile: 'Bike name or profile', - forkLsc: '0', - forkHsc: '0', - forkLsr: '0', - forkHsr: '0', - shockLsc: '0', - shockHsc: '0', - shockLsr: '0', - shockHsr: '0', - id: 0, -}; - -const columns = [ - { key: 'profile', title: 'Profile', dataType: DataType.String, width: '30%' }, - { key: 'forkLsc', title: 'Fork LSC', dataType: DataType.String }, - { key: 'forkHsc', title: 'Fork HSC', dataType: DataType.String }, - { key: 'forkLsr', title: 'Fork LSR', dataType: DataType.String }, - { key: 'forkHsr', title: 'Fork HSR', dataType: DataType.String }, - { key: 'shockLsc', title: 'Shock LSC', dataType: DataType.String }, - { key: 'shockHsc', title: 'Shock HSC', dataType: DataType.String }, - { key: 'shockLsr', title: 'Shock LSR', dataType: DataType.String }, - { key: 'shockHsr', title: 'Shock HSR', dataType: DataType.String }, - { key: 'actions', style: {width: 80}}, -]; - -const SuspenseTable: React.FC = () => { - const [tableData, setTableData] = useLocalStorage(LOCAL_STORAGE_KEY, [blankRow]); - - let maxValue = Math.max(...tableData.map(i => i.id)); - const generateNewId = () => { - maxValue++; - return maxValue; - }; - const AddButton: React.FC = ({ - dispatch, - }) => { - return ( -
- Add New Row dispatch(showNewRow())} - /> -
- ); - }; - - const DeleteRow: React.FC = ({ - dispatch, rowKeyValue, - }) => { - return ( - dispatch(deleteRow(rowKeyValue))} - alt='' - /> - ); - }; - - const RemoveButton: React.FC = ({ - dispatch - }) => { - return ( - Cancel dispatch(hideNewRow())} - /> - ); - }; - - const SaveButton: React.FC = ({ - dispatch - }) => { - const saveNewData = () => { - const rowKeyValue = generateNewId(); - dispatch(saveNewRow(rowKeyValue, { - validate: true - })); - }; - return ( - Save - ); - }; - - const tablePropsInit: ITableProps = { - columns: columns, - data: tableData, - editingMode: EditingMode.Cell, - rowKeyField: 'id', - sortingMode: SortingMode.Single, - }; - - const [tableProps, changeTableProps] = useState(tablePropsInit); - - const dispatch: DispatchFunc = (action) => { - changeTableProps((prevState: ITableProps) => { - setTableData(kaReducer(prevState, action).data); - return kaReducer(prevState, action) - }); - }; - - return ( - { - if (props.column.key === 'actions'){ - return ( -
- - -
- ); - } - } - }, - cellText: { - content: (props) => { - if (props.column.key === 'actions') { - return ; - } - } - }, - headCell: { - content: (props) => { - if (props.column.key === 'actions'){ - return ; - } - } - } - }} - /> - ); -}; - -export default SuspenseTable; - diff --git a/app/components/title.tsx b/app/components/title.tsx deleted file mode 100644 index a9ad3d3..0000000 --- a/app/components/title.tsx +++ /dev/null @@ -1,16 +0,0 @@ -export default function Title({ - text, description -} : { - text: string, - description: string -}) { - return ( -
-

{text}

-
- {description} -
-
- ) -}; - From 8f136d53904457eb0aa73d85921ebedfdf7fd823 Mon Sep 17 00:00:00 2001 From: Steve Laing Date: Tue, 2 Jan 2024 16:20:48 +0000 Subject: [PATCH 04/21] Define Profile model --- app/types/index.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 app/types/index.ts diff --git a/app/types/index.ts b/app/types/index.ts new file mode 100644 index 0000000..dad1eef --- /dev/null +++ b/app/types/index.ts @@ -0,0 +1,16 @@ +export interface ProfileModel { + id: number, + name: string, + forkPsi: number, + forkHsc: number, + forkLsc: number, + forkHsr: number, + forkLsr: number, + forkSag: number, + shockPsi: number, + shockHsc: number, + shockLsc: number, + shockHsr: number, + shockLsr: number, + shockSag: number, +} From 552582ae3acfa4d15dc277ba156c593018d78510 Mon Sep 17 00:00:00 2001 From: Steve Laing Date: Tue, 2 Jan 2024 16:21:21 +0000 Subject: [PATCH 05/21] Remove old favicon --- app/favicon.ico | Bin 25931 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 app/favicon.ico diff --git a/app/favicon.ico b/app/favicon.ico deleted file mode 100644 index 718d6fea4835ec2d246af9800eddb7ffb276240c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 25931 zcmeHv30#a{`}aL_*G&7qml|y<+KVaDM2m#dVr!KsA!#An?kSQM(q<_dDNCpjEux83 zLb9Z^XxbDl(w>%i@8hT6>)&Gu{h#Oeyszu?xtw#Zb1mO{pgX9699l+Qppw7jXaYf~-84xW z)w4x8?=youko|}Vr~(D$UXIbiXABHh`p1?nn8Po~fxRJv}|0e(BPs|G`(TT%kKVJAdg5*Z|x0leQq0 zkdUBvb#>9F()jo|T~kx@OM8$9wzs~t2l;K=woNssA3l6|sx2r3+kdfVW@e^8e*E}v zA1y5{bRi+3Z`uD3{F7LgFJDdvm;nJilkzDku>BwXH(8ItVCXk*-lSJnR?-2UN%hJ){&rlvg`CDTj z)Bzo!3v7Ou#83zEDEFcKt(f1E0~=rqeEbTnMvWR#{+9pg%7G8y>u1OVRUSoox-ovF z2Ydma(;=YuB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 +0000 Subject: [PATCH 06/21] Add a JSON response fetcher --- app/lib/index.ts | 1 + 1 file changed, 1 insertion(+) create mode 100644 app/lib/index.ts diff --git a/app/lib/index.ts b/app/lib/index.ts new file mode 100644 index 0000000..50b047c --- /dev/null +++ b/app/lib/index.ts @@ -0,0 +1 @@ +export const fetcher = (url: string) => fetch(url).then((res) => res.json()); From 7fdb960fab1e767d1d2eb82ea13295f91cc5cd9e Mon Sep 17 00:00:00 2001 From: Steve Laing Date: Tue, 2 Jan 2024 16:37:30 +0000 Subject: [PATCH 07/21] Add favicon in correct location --- favicon.ico | Bin 0 -> 25931 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 favicon.ico diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..718d6fea4835ec2d246af9800eddb7ffb276240c GIT binary patch literal 25931 zcmeHv30#a{`}aL_*G&7qml|y<+KVaDM2m#dVr!KsA!#An?kSQM(q<_dDNCpjEux83 zLb9Z^XxbDl(w>%i@8hT6>)&Gu{h#Oeyszu?xtw#Zb1mO{pgX9699l+Qppw7jXaYf~-84xW z)w4x8?=youko|}Vr~(D$UXIbiXABHh`p1?nn8Po~fxRJv}|0e(BPs|G`(TT%kKVJAdg5*Z|x0leQq0 zkdUBvb#>9F()jo|T~kx@OM8$9wzs~t2l;K=woNssA3l6|sx2r3+kdfVW@e^8e*E}v zA1y5{bRi+3Z`uD3{F7LgFJDdvm;nJilkzDku>BwXH(8ItVCXk*-lSJnR?-2UN%hJ){&rlvg`CDTj z)Bzo!3v7Ou#83zEDEFcKt(f1E0~=rqeEbTnMvWR#{+9pg%7G8y>u1OVRUSoox-ovF z2Ydma(;=YuBY(eI|04{hXzZD6_f(v~H;C~y5=DhAC{MMS>2fm~1H_t2$56pc$NH8( z5bH|<)71dV-_oCHIrzrT`2s-5w_+2CM0$95I6X8p^r!gHp+j_gd;9O<1~CEQQGS8) zS9Qh3#p&JM-G8rHekNmKVewU;pJRcTAog68KYo^dRo}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^{++3MY>}W_uq7jGHx{mwE9fZiPCoxN$+7 zrODGGJrOkcPQUB(FD5aoS4g~7#6NR^ma7-!>mHuJfY5kTe6PpNNKC9GGRiu^L31uG z$7v`*JknQHsYB!Tm_W{a32TM099djW%5e+j0Ve_ct}IM>XLF1Ap+YvcrLV=|CKo6S zb+9Nl3_YdKP6%Cxy@6TxZ>;4&nTneadr z_ES90ydCev)LV!dN=#(*f}|ZORFdvkYBni^aLbUk>BajeWIOcmHP#8S)*2U~QKI%S zyrLmtPqb&TphJ;>yAxri#;{uyk`JJqODDw%(Z=2`1uc}br^V%>j!gS)D*q*f_-qf8&D;W1dJgQMlaH5er zN2U<%Smb7==vE}dDI8K7cKz!vs^73o9f>2sgiTzWcwY|BMYHH5%Vn7#kiw&eItCqa zIkR2~Q}>X=Ar8W|^Ms41Fm8o6IB2_j60eOeBB1Br!boW7JnoeX6Gs)?7rW0^5psc- zjS16yb>dFn>KPOF;imD}e!enuIniFzv}n$m2#gCCv4jM#ArwlzZ$7@9&XkFxZ4n!V zj3dyiwW4Ki2QG{@i>yuZXQizw_OkZI^-3otXC{!(lUpJF33gI60ak;Uqitp74|B6I zgg{b=Iz}WkhCGj1M=hu4#Aw173YxIVbISaoc z-nLZC*6Tgivd5V`K%GxhBsp@SUU60-rfc$=wb>zdJzXS&-5(NRRodFk;Kxk!S(O(a0e7oY=E( zAyS;Ow?6Q&XA+cnkCb{28_1N8H#?J!*$MmIwLq^*T_9-z^&UE@A(z9oGYtFy6EZef LrJugUA?W`A8`#=m literal 0 HcmV?d00001 From 8fb4a51e56161c7ed28bb10e48352dc1ce2ada51 Mon Sep 17 00:00:00 2001 From: Steve Laing Date: Wed, 31 Jan 2024 13:16:39 +0000 Subject: [PATCH 08/21] Add a service to read and write to profiles data --- data/profiles.json | 1 + pages/api/profilesRepo.js | 70 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 data/profiles.json create mode 100644 pages/api/profilesRepo.js diff --git a/data/profiles.json b/data/profiles.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/data/profiles.json @@ -0,0 +1 @@ +[] diff --git a/pages/api/profilesRepo.js b/pages/api/profilesRepo.js new file mode 100644 index 0000000..ccf82b1 --- /dev/null +++ b/pages/api/profilesRepo.js @@ -0,0 +1,70 @@ +const fs = require('fs'); + +let profiles = require('./../../data/profiles.json'); + +const getAll = () => { + return profiles; +} + +const getById = (id) => { + return profiles.find(x => x.id.toString() === id.toString()); +} + +const create = ({ name, forkPsi, forkSag, forkHsc, forkLsc, forkHsr, forkLsr, shockPsi, shockSag, shockHsc, shockLsc, shockHsr, shockLsr }) => { + const profile = { name, forkPsi, forkSag, forkHsc, forkLsc, forkHsr, forkLsr, shockPsi, shockSag, shockHsc, shockLsc, shockHsr, shockLsr }; + + // validate + if (profiles.find(x => x.name === profile.name)) + throw `Profile with the name ${profile.name} already exists`; + + // generate new profile id + profile.id = profiles.length ? Math.max(...profiles.map(x => x.id)) + 1 : 1; + + // set date created and updated + profile.dateCreated = new Date().toISOString(); + profile.dateUpdated = new Date().toISOString(); + + // add and save profile + profiles.push(profile); + saveData(); +} + +const update = (id, { name, forkPsi, forkSag, forkHsc, forkLsc, forkHsr, forkLsr, shockPsi, shockSag, shockHsc, shockLsc, shockHsr, shockLsr }) => { + const params = { name, forkPsi, forkSag, forkHsc, forkLsc, forkHsr, forkLsr, shockPsi, shockSag, shockHsc, shockLsc, shockHsr, shockLsr }; + const profile = profiles.find(x => x.id.toString() === id.toString()); + + // validate + if (params.name !== profile.name && profiles.find(x => x.name === params.name)) + throw `Profile with the name ${params.name} already exists`; + + // set date updated + profile.dateUpdated = new Date().toISOString(); + + // update and save + Object.assign(profile, params); + saveData(); +} + +// prefixed with underscore '_' because 'delete' is a reserved word in javascript +const _delete = (id) => { + // filter out deleted profile and save + profiles = profiles.filter(x => x.id.toString() !== id.toString()); + saveData(); + +} + +// private helper functions + +const saveData = () => { + fs.writeFileSync('data/profiles.json', JSON.stringify(profiles, null, 4)); +} + +const profilesRepo = { + getAll, + getById, + create, + update, + delete: _delete +}; + +export default profilesRepo; From 3ddedb9c32762787eaf47569dd1f5b34da52c051 Mon Sep 17 00:00:00 2001 From: Steve Laing Date: Wed, 31 Jan 2024 13:17:15 +0000 Subject: [PATCH 09/21] Add API for profiles CRUD operations --- pages/api/profiles.ts | 31 ++++++++++++++++++++++++++++++ pages/api/profiles/[id].ts | 39 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 pages/api/profiles.ts create mode 100644 pages/api/profiles/[id].ts diff --git a/pages/api/profiles.ts b/pages/api/profiles.ts new file mode 100644 index 0000000..9d9d555 --- /dev/null +++ b/pages/api/profiles.ts @@ -0,0 +1,31 @@ +import profilesRepo from './profilesRepo'; + +import type { NextApiRequest, NextApiResponse } from 'next' + +export default function handler( + req: NextApiRequest, + res: NextApiResponse +) { + const getProfiles = () => { + const profiles = profilesRepo.getAll(); + return res.status(200).json(profiles); + } + + const createProfile = () => { + try { + profilesRepo.create(req.body); + return res.status(200).json({}); + } catch (error: any) { + return res.status(400).json({ message: error }); + } + } + + switch (req.method) { + case 'GET': + return getProfiles(); + case 'POST': + return createProfile(); + default: + return res.status(405).end(`Method ${req.method} Not Allowed`) + } +} diff --git a/pages/api/profiles/[id].ts b/pages/api/profiles/[id].ts new file mode 100644 index 0000000..b0bc5f8 --- /dev/null +++ b/pages/api/profiles/[id].ts @@ -0,0 +1,39 @@ +import profilesRepo from './../profilesRepo'; + +import type { NextApiRequest, NextApiResponse } from 'next' + +export default function handler( + req: NextApiRequest, + res: NextApiResponse +) { + + const getProfileById = () => { + const profile = profilesRepo.getById(req.query.id); + return res.status(200).json(profile); + } + + const updateProfile = () => { + try { + profilesRepo.update(req.query.id, req.body); + return res.status(200).json({}); + } catch (error) { + return res.status(400).json({ message: error }); + } + } + + const deleteProfile = () => { + profilesRepo.delete(req.query.id); + return res.status(200).json({}); + } + + switch (req.method) { + case 'GET': + return getProfileById(); + case 'PUT': + return updateProfile(); + case 'DELETE': + return deleteProfile(); + default: + return res.status(405).end(`Method ${req.method} Not Allowed`) + } +} From 3fa5940906e9e0e58dd0a9fd39af01062fd89640 Mon Sep 17 00:00:00 2001 From: Steve Laing Date: Wed, 31 Jan 2024 13:18:16 +0000 Subject: [PATCH 10/21] Add frontend CRUD actions for profiles --- app/profiles/create/page.tsx | 199 +++++++++++++++++++++++++++++ app/profiles/edit/[id]/page.tsx | 220 ++++++++++++++++++++++++++++++++ app/profiles/page.tsx | 62 +++++++++ app/profiles/read/[id]/page.tsx | 69 ++++++++++ 4 files changed, 550 insertions(+) create mode 100644 app/profiles/create/page.tsx create mode 100644 app/profiles/edit/[id]/page.tsx create mode 100644 app/profiles/page.tsx create mode 100644 app/profiles/read/[id]/page.tsx diff --git a/app/profiles/create/page.tsx b/app/profiles/create/page.tsx new file mode 100644 index 0000000..ad2b5aa --- /dev/null +++ b/app/profiles/create/page.tsx @@ -0,0 +1,199 @@ +"use client" +import React, {useState } from 'react' +import { useRouter } from 'next/navigation' +export default function ProfileCreate() { + const router = useRouter() + const [name, setName] = useState(''); + const [forkPsi, setForkPsi] = useState(''); + const [forkSag, setForkSag] = useState(''); + const [forkHsc, setForkHsc] = useState(''); + const [forkLsc, setForkLsc] = useState(''); + const [forkHsr, setForkHsr] = useState(''); + const [forkLsr, setForkLsr] = useState(''); + const [shockPsi, setShockPsi] = useState(''); + const [shockSag, setShockSag] = useState(''); + const [shockHsc, setShockHsc] = useState(''); + const [shockLsc, setShockLsc] = useState(''); + const [shockHsr, setShockHsr] = useState(''); + const [shockLsr, setShockLsr] = useState(''); + + const addProfile = async (e: any) => { + e.preventDefault() + if (name != "") { + const formData = { + name: name, + forkPsi: forkPsi, + forkSag: forkSag, + forkHsc: forkHsc, + forkLsc: forkLsc, + forkHsr: forkHsr, + forkLsr: forkLsr, + shockPsi: shockPsi, + shockSag: shockSag, + shockHsc: shockHsc, + shockLsc: shockLsc, + shockHsr: shockHsr, + shockLsr: shockLsr + } + const add = await fetch('/api/profiles', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(formData) + }); + const content = await add.json(); + if(content.success>0) + { + router.push('/profile'); + } + + } + }; + + const labelClassNames = 'block text-gray-500 font-bold md:text-right mb-1 md:mb-0 pr-4'; + const inputClassNames = 'bg-gray-200 appearance-none border-2 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-blue-500'; + + return ( +
+

Add profile

+
+
+ +
+
+ setName(e.target.value)}/> +
+
+
+
+ +
+
+ setForkPsi(e.target.value)}/> +
+
+
+
+ +
+
+ setForkSag(e.target.value)}/> +
+
+
+
+ +
+
+ setForkHsc(e.target.value)}/> +
+
+
+
+ +
+
+ setForkLsc(e.target.value)}/> +
+
+
+
+ +
+
+ setForkHsr(e.target.value)}/> +
+
+
+
+ +
+
+ setForkLsr(e.target.value)}/> +
+
+
+
+ +
+
+ setShockPsi(e.target.value)}/> +
+
+
+
+ +
+
+ setShockSag(e.target.value)}/> +
+
+ +
+
+ +
+
+ setShockHsc(e.target.value)}/> +
+
+
+
+ +
+
+ setShockLsc(e.target.value)}/> +
+
+
+
+ +
+
+ setShockHsr(e.target.value)}/> +
+
+
+
+ +
+
+ setShockLsr(e.target.value)}/> +
+
+ +
+ +
+ + ) +} + + diff --git a/app/profiles/edit/[id]/page.tsx b/app/profiles/edit/[id]/page.tsx new file mode 100644 index 0000000..9fd0f32 --- /dev/null +++ b/app/profiles/edit/[id]/page.tsx @@ -0,0 +1,220 @@ +"use client" +import React, {useState,useEffect } from 'react' +import { useRouter } from 'next/navigation' +import { fetcher } from '@/app/lib' +import useSWR from 'swr' + +export default function ProfileEdit({params} :{params:{id:number}}) { + const router = useRouter() + const [name, setName] = useState(''); + const [forkPsi, setForkPsi] = useState(''); + const [forkSag, setForkSag] = useState(''); + const [forkHsc, setForkHsc] = useState(''); + const [forkLsc, setForkLsc] = useState(''); + const [forkHsr, setForkHsr] = useState(''); + const [forkLsr, setForkLsr] = useState(''); + const [shockPsi, setShockPsi] = useState(''); + const [shockSag, setShockSag] = useState(''); + const [shockHsc, setShockHsc] = useState(''); + const [shockLsc, setShockLsc] = useState(''); + const [shockHsr, setShockHsr] = useState(''); + const [shockLsr, setShockLsr] = useState(''); + + const {data : profile,isLoading, error} = useSWR(`/api/profiles/${params.id}`,fetcher) + useEffect(()=>{ + if(profile){ + setName(profile.name) + setForkPsi(profile.forkPsi) + setForkSag(profile.forkSag) + setForkHsc(profile.forkHsc) + setForkLsc(profile.forkLsc) + setForkHsr(profile.forkHsr) + setForkLsr(profile.forkLsr) + setShockPsi(profile.shockPsi) + setShockSag(profile.shockSag) + setShockHsc(profile.shockHsc) + setShockLsc(profile.shockLsc) + setShockHsr(profile.shockHsr) + setShockLsr(profile.shockLsr) + } + },[profile, isLoading]) + const updateProfile = async (e: any) => { + e.preventDefault() + if (name != "" && forkPsi != "" && shockPsi != "") { + const formData = { + name: name, + forkPsi: forkPsi, + forkSag: forkSag, + forkHsc: forkHsc, + forkLsc: forkLsc, + forkHsr: forkHsr, + forkLsr: forkLsr, + shockPsi: shockPsi, + shockSag: shockSag, + shockHsc: shockHsc, + shockLsc: shockLsc, + shockHsr: shockHsr, + shockLsr: shockLsr + } + const res = await fetch(`/api/profiles/${params.id}`, { + method: 'PUT', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(formData) + }); + const content = await res.json(); + if(content.success>0) + { + router.push('/profile'); + } + + } + }; + if(isLoading) return
Loading...
+ if (!profile) return null; + const labelClassNames = 'block text-gray-500 font-bold md:text-right mb-1 md:mb-0 pr-4'; + const inputClassNames = 'bg-gray-200 appearance-none border-2 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-blue-500'; + + return ( +
+

Edit profile

+
+
+ +
+
+ setName(e.target.value)}/> +
+
+
+
+ +
+
+ setForkPsi(e.target.value)}/> +
+
+
+
+ +
+
+ setForkSag(e.target.value)}/> +
+
+
+
+ +
+
+ seForkHsc(e.target.value)}/> +
+
+
+
+ +
+
+ setForkLsc(e.target.value)}/> +
+
+
+
+ +
+
+ setForkHsr(e.target.value)}/> +
+
+
+
+ +
+
+ setForkLsr(e.target.value)}/> +
+
+
+
+ +
+
+ setShockPsi(e.target.value)}/> +
+
+
+
+ +
+
+ setShockSag(e.target.value)}/> +
+
+ +
+
+ +
+
+ setShockHsc(e.target.value)}/> +
+
+
+
+ +
+
+ setShockLsc(e.target.value)}/> +
+
+
+
+ +
+
+ setShockHsr(e.target.value)}/> +
+
+
+
+ +
+
+ setShockLsr(e.target.value)}/> +
+
+ +
+ +
+ + ) +} + diff --git a/app/profiles/page.tsx b/app/profiles/page.tsx new file mode 100644 index 0000000..185f557 --- /dev/null +++ b/app/profiles/page.tsx @@ -0,0 +1,62 @@ +"use client"; +import React,{useEffect, useState} from "react"; +import useSWR from "swr"; +import { fetcher } from "../lib"; +import Profile from "../components/Profile"; +import { ProfileModel } from "../types"; +import Link from "next/link"; + +export default function Profiles() { + const [profiles,setProfiles] = useState([]); + const { data, error, isLoading } = useSWR(`/api/profiles`, fetcher); + useEffect(()=>{ + if(data) + { + setProfiles(data); + } + },[data,isLoading]); + if (error) return
Failed to load
; + if (isLoading) return
Loading...
; + if (!data) return null; + let delete_Profile : ProfileModel['deleteProfile']= async (id:number) => { + const res = await fetch(`/api/profiles/${id}`, { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json' + }, + }); + const content = await res.json(); + if(content.success>0) + { + + setProfiles(profiles?.filter((profile:ProfileModel)=>{ return profile.id !== id })); + } + } + return ( +
+
+ + + + + + + + + + + + { + profiles && profiles.map((item : ProfileModel)=>) + } + + + + +
NameFork PSIFork SagShock PSIShock SagAction
+ Create +
+ + ); +} + diff --git a/app/profiles/read/[id]/page.tsx b/app/profiles/read/[id]/page.tsx new file mode 100644 index 0000000..311552c --- /dev/null +++ b/app/profiles/read/[id]/page.tsx @@ -0,0 +1,69 @@ +'use client' +import { fetcher } from '@/app/lib' +import useSWR from 'swr' + +export default function Detail({params}: {params:{id :number}}) { + const {data: profile, isLoading, error} = useSWR(`/api/profiles/${params.id}`,fetcher) + if(isLoading) return
Loading...
+ if (!profile) return null; + return ( +
+

{profile.name}

+ +
+
+
+
Fork PSI
+
{profile.forkPsi}
+
+
+
Fork sag
+
{profile.forkSag}%
+
+
+
Fork HSC
+
{profile.forkHsc}
+
+
+
Fork LSC
+
{profile.forkLsc}
+
+
+
Fork HSR
+
{profile.forkHsr}
+
+
+
Fork LSR
+
{profile.forkLsr}
+
+
+
Shock PSI
+
{profile.shockPsi}
+
+
+
Shock sag
+
{profile.shockSag}
+
+
+
Shock HSC
+
{profile.shockHsc}
+
+
+
Shock LSC
+
{profile.shockLsc}
+
+
+
Shock HSR
+
{profile.shockHsr}
+
+
+
Shock LSR
+
{profile.shockLsr}
+
+
+
+
+ ) +} + + From 9e900af4bd1338316ff9447b61acef0f47f6c60b Mon Sep 17 00:00:00 2001 From: Steve Laing Date: Wed, 31 Jan 2024 13:19:14 +0000 Subject: [PATCH 11/21] Refactor layout and other frontend components Simplify and refactor profiles to work in a standard CRUD pattern using the underlying profiles API and CRUD actions. --- app/components/Header.tsx | 10 ++++++++++ app/components/Profile.tsx | 21 +++++++++++++++++++++ app/globals.css | 24 ------------------------ app/layout.tsx | 12 +++++++++--- app/page.tsx | 16 +++------------- index.tsx | 13 +++++++++++++ jsconfig.json | 6 ++++++ 7 files changed, 62 insertions(+), 40 deletions(-) create mode 100644 app/components/Header.tsx create mode 100644 app/components/Profile.tsx create mode 100644 index.tsx create mode 100644 jsconfig.json diff --git a/app/components/Header.tsx b/app/components/Header.tsx new file mode 100644 index 0000000..d4cea35 --- /dev/null +++ b/app/components/Header.tsx @@ -0,0 +1,10 @@ +import React from 'react' + +export default function Header() { + return ( +
+

Suspense

+

Record your suspension settings

+
+ ) +} diff --git a/app/components/Profile.tsx b/app/components/Profile.tsx new file mode 100644 index 0000000..2181217 --- /dev/null +++ b/app/components/Profile.tsx @@ -0,0 +1,21 @@ +import React from 'react' +import { ProfileModel } from '../types' +import Link from 'next/link' +export default function Profile(params: ProfileModel) { + return ( + + + {params.name} + + {params.forkPsi} + {params.forkSag}% + {params.shockPsi} + {params.shockSag}% + + Edit + params.deleteProfile(params.id)} className='bg-red-500 ml-3 p-2 inline-block text-white text-sm'>Delete + + + ) +} + diff --git a/app/globals.css b/app/globals.css index fd81e88..b5c61c9 100644 --- a/app/globals.css +++ b/app/globals.css @@ -1,27 +1,3 @@ @tailwind base; @tailwind components; @tailwind utilities; - -:root { - --foreground-rgb: 0, 0, 0; - --background-start-rgb: 214, 219, 220; - --background-end-rgb: 255, 255, 255; -} - -@media (prefers-color-scheme: dark) { - :root { - --foreground-rgb: 255, 255, 255; - --background-start-rgb: 0, 0, 0; - --background-end-rgb: 0, 0, 0; - } -} - -body { - color: rgb(var(--foreground-rgb)); - background: linear-gradient( - to bottom, - transparent, - rgb(var(--background-end-rgb)) - ) - rgb(var(--background-start-rgb)); -} diff --git a/app/layout.tsx b/app/layout.tsx index f37a270..badec46 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,12 +1,13 @@ import './globals.css' import type { Metadata } from 'next' import { Inter } from 'next/font/google' +import Header from './components/Header' const inter = Inter({ subsets: ['latin'] }) export const metadata: Metadata = { - title: 'Suspense', - description: 'Record your suspension settings', + title: 'Create Next App', + description: 'Generated by create next app', } export default function RootLayout({ @@ -16,7 +17,12 @@ export default function RootLayout({ }) { return ( - {children} + +
+
+ {children} +
+ ) } diff --git a/app/page.tsx b/app/page.tsx index 61ff6b1..209125c 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,17 +1,7 @@ -import Image from 'next/image' -import Title from './components/title' -import dynamic from 'next/dynamic' -const SuspenseTable = dynamic(() => import('./components/suspense-table'), { ssr: false }); - +import Profiles from './profiles/page' export default function Home() { return ( -
-
- - </div> - <div className="z-10 max-w-10xl w-full items-center font-mono text-sm lg:flex"> - <SuspenseTable /> - </div> - </main> + <Profiles /> ) } + diff --git a/index.tsx b/index.tsx new file mode 100644 index 0000000..c880492 --- /dev/null +++ b/index.tsx @@ -0,0 +1,13 @@ +import { Link } from 'components'; + +export default Home; + +function Home() { + return ( + <div> + <h1>Next.js 10 - CRUD Example with React Hook Form</h1> + <p>An example app showing how to list, add, edit and delete user records with Next.js 10 and the React Hook Form library.</p> + <p><Link href="/profiles">>> Manage Profiles</Link></p> + </div> + ); +} diff --git a/jsconfig.json b/jsconfig.json new file mode 100644 index 0000000..d056459 --- /dev/null +++ b/jsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + // make all imports without a dot '.' prefix relative to the base url + "baseUrl": "." + } +} From 0a56a33e05e8c5db49a7508c1a4111f428f53d32 Mon Sep 17 00:00:00 2001 From: Steve Laing <steve.laing@gmail.com> Date: Wed, 31 Jan 2024 14:42:39 +0000 Subject: [PATCH 12/21] Add common form components --- app/components/form/Label.tsx | 16 +++ app/components/form/LabelAndTextField.tsx | 24 ++++ app/components/form/Submit.tsx | 9 ++ app/components/form/TextField.tsx | 19 +++ app/profiles/create/page.tsx | 164 +++------------------- 5 files changed, 90 insertions(+), 142 deletions(-) create mode 100644 app/components/form/Label.tsx create mode 100644 app/components/form/LabelAndTextField.tsx create mode 100644 app/components/form/Submit.tsx create mode 100644 app/components/form/TextField.tsx diff --git a/app/components/form/Label.tsx b/app/components/form/Label.tsx new file mode 100644 index 0000000..f32935b --- /dev/null +++ b/app/components/form/Label.tsx @@ -0,0 +1,16 @@ +import React from 'react' + +interface LabelProps { + fieldName: string; + labelText: string; +} + +export default function Label({fieldName, labelText}: LabelProps) { + const classNames = 'block text-gray-500 font-bold md:text-right mb-1 md:mb-0 pr-4'; + + return ( + <label className={classNames} htmlFor={fieldName}> + {labelText} + </label> + ) +} diff --git a/app/components/form/LabelAndTextField.tsx b/app/components/form/LabelAndTextField.tsx new file mode 100644 index 0000000..ca777a1 --- /dev/null +++ b/app/components/form/LabelAndTextField.tsx @@ -0,0 +1,24 @@ +import React from 'react' +import { SyntheticEvent } from 'react' +import Label from './Label' +import TextField from './TextField' + +interface LabelAndTextFieldProps { + fieldName: string; + fieldSetter: Function; + labelText: string; +} + +export default function LabelAndTextField({fieldName, fieldSetter, labelText}: LabelAndTextFieldProps) { + + return ( + <div className="md:flex md:items-center mb-6"> + <div className="md:w-1/4"> + <Label fieldName={fieldName} labelText={labelText} /> + </div> + <div className="md:w-2/4"> + <TextField fieldName={fieldName} fieldSetter={fieldSetter} /> + </div> + </div> + ) +} diff --git a/app/components/form/Submit.tsx b/app/components/form/Submit.tsx new file mode 100644 index 0000000..1aa2a40 --- /dev/null +++ b/app/components/form/Submit.tsx @@ -0,0 +1,9 @@ +import React from 'react' + +export default function Submit() { + return ( + <div className='w-full py-2 text-center'> + <button className="w-20 p-2 text-white border-gray-200 border-[1px] rounded-sm bg-green-400">Submit</button> + </div> + ) +} diff --git a/app/components/form/TextField.tsx b/app/components/form/TextField.tsx new file mode 100644 index 0000000..f4014e0 --- /dev/null +++ b/app/components/form/TextField.tsx @@ -0,0 +1,19 @@ +import React from 'react' +import { SyntheticEvent } from 'react' + +interface TextFieldProps { + fieldName: string; + fieldSetter: Function; +} + +export default function TextField({fieldName, fieldSetter}: TextFieldProps) { + const classNames = 'bg-gray-200 appearance-none border-2 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-blue-500'; + + const onChange = (e: React.ChangeEvent<HTMLInputElement>): void => { + fieldSetter(e.currentTarget.value); + } + + return ( + <input className={classNames} id={fieldName} type="text" onChange={onChange}/> + ) +} diff --git a/app/profiles/create/page.tsx b/app/profiles/create/page.tsx index ad2b5aa..4142d6f 100644 --- a/app/profiles/create/page.tsx +++ b/app/profiles/create/page.tsx @@ -1,6 +1,9 @@ "use client" import React, {useState } from 'react' import { useRouter } from 'next/navigation' +import LabelAndTextField from '../../components/form/LabelAndTextField' +import Submit from '../../components/form/Submit' + export default function ProfileCreate() { const router = useRouter() const [name, setName] = useState<string>(''); @@ -43,157 +46,34 @@ export default function ProfileCreate() { body: JSON.stringify(formData) }); const content = await add.json(); - if(content.success>0) - { - router.push('/profile'); + if(content.success > 0) { + router.push(`/profiles/read/${content.id}`); } - } }; - const labelClassNames = 'block text-gray-500 font-bold md:text-right mb-1 md:mb-0 pr-4'; - const inputClassNames = 'bg-gray-200 appearance-none border-2 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-blue-500'; - return ( <form className="w-full bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4" onSubmit={addProfile}> - <h1 className="text-xl font-bold">Add profile</h1> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="name"> - Name - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="name" type="text" onChange={(e:any)=>setName(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="forkPsi"> - Fork PSI - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="forkPsi" type="text" onChange={(e:any)=>setForkPsi(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="forkSag"> - Fork sag - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="forkSag" type="text" onChange={(e:any)=>setForkSag(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="forkHsc"> - Fork HSC - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="forkHsc" type="text" onChange={(e:any)=>setForkHsc(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="forkLsc"> - Fork LSC - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="forkLsc" type="text" onChange={(e:any)=>setForkLsc(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="forkHsr"> - Fork HSR - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="forkHsr" type="text" onChange={(e:any)=>setForkHsr(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="forkLsr"> - Fork LSR - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="forkLsr" type="text" onChange={(e:any)=>setForkLsr(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="shockPsi"> - Shock PSI - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="shockPsi" type="text" onChange={(e:any)=>setShockPsi(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="shockSag"> - Shock sag - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="shockSag" type="text" onChange={(e:any)=>setShockSag(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="shockHsc"> - Shock HSC - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="shockHsc" type="text" onChange={(e:any)=>setShockHsc(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="shockLsc"> - Shock LSC - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="shockLsc" type="text" onChange={(e:any)=>setShockLsc(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="shockHsr"> - Shock HSR - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="shockHsr" type="text" onChange={(e:any)=>setShockHsr(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="shockLsr"> - Shock LSR - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="shockLsr" type="text" onChange={(e:any)=>setShockLsr(e.target.value)}/> - </div> + <div className="m-auto w-full text-center mb-10"> + <h1 className="text-xl font-bold">Add a new suspension profile</h1> </div> - <div className='w-full py-2'> - <button className="w-20 p-2 text-white border-gray-200 border-[1px] rounded-sm bg-green-400">Submit</button> - </div> + <LabelAndTextField fieldName={'name'} fieldSetter={setName} labelText={'Name'} /> + <LabelAndTextField fieldName={'forkPsi'} fieldSetter={setForkPsi} labelText={'Fork PSI'} /> + <LabelAndTextField fieldName={'forkSag'} fieldSetter={setForkSag} labelText={'Fork sag'} /> + <LabelAndTextField fieldName={'forkHsc'} fieldSetter={setForkHsc} labelText={'Fork HSC'} /> + <LabelAndTextField fieldName={'forkLsc'} fieldSetter={setForkLsc} labelText={'Fork LSC'} /> + <LabelAndTextField fieldName={'forkHsr'} fieldSetter={setForkHsr} labelText={'Fork HSR'} /> + <LabelAndTextField fieldName={'forkLsr'} fieldSetter={setForkLsr} labelText={'Fork LSR'} /> + <LabelAndTextField fieldName={'shockPsi'} fieldSetter={setShockPsi} labelText={'Shock PSI'} /> + <LabelAndTextField fieldName={'shockSag'} fieldSetter={setShockSag} labelText={'Shock sag'} /> + <LabelAndTextField fieldName={'shockHsc'} fieldSetter={setShockHsc} labelText={'Shock HSC'} /> + <LabelAndTextField fieldName={'shockLsc'} fieldSetter={setShockLsc} labelText={'Shock LSC'} /> + <LabelAndTextField fieldName={'shockHsr'} fieldSetter={setShockHsr} labelText={'Shock HSR'} /> + <LabelAndTextField fieldName={'shockLsr'} fieldSetter={setShockLsr} labelText={'Shock LSR'} /> + + <Submit /> </form> ) } - - From 594344a8a08b72b07895d26b046f2d8d4d624d30 Mon Sep 17 00:00:00 2001 From: Steve Laing <steve.laing@gmail.com> Date: Wed, 21 Feb 2024 11:11:11 +0000 Subject: [PATCH 13/21] Use common components on edit form --- app/components/form/Label.tsx | 2 +- app/components/form/LabelAndTextField.tsx | 5 +- app/components/form/TextField.tsx | 4 +- app/profiles/edit/[id]/page.tsx | 158 +++------------------- app/profiles/page.tsx | 16 +-- index.tsx | 7 +- 6 files changed, 27 insertions(+), 165 deletions(-) diff --git a/app/components/form/Label.tsx b/app/components/form/Label.tsx index f32935b..045b3b9 100644 --- a/app/components/form/Label.tsx +++ b/app/components/form/Label.tsx @@ -1,6 +1,6 @@ import React from 'react' -interface LabelProps { +interface LabelProps extends React.HTMLAttributes<any> { fieldName: string; labelText: string; } diff --git a/app/components/form/LabelAndTextField.tsx b/app/components/form/LabelAndTextField.tsx index ca777a1..fc2ac35 100644 --- a/app/components/form/LabelAndTextField.tsx +++ b/app/components/form/LabelAndTextField.tsx @@ -3,14 +3,13 @@ import { SyntheticEvent } from 'react' import Label from './Label' import TextField from './TextField' -interface LabelAndTextFieldProps { +interface LabelAndTextFieldProps extends React.HTMLAttributes<any> { fieldName: string; - fieldSetter: Function; + fieldSetter: React.Dispatch<React.SetStateAction<string>>; labelText: string; } export default function LabelAndTextField({fieldName, fieldSetter, labelText}: LabelAndTextFieldProps) { - return ( <div className="md:flex md:items-center mb-6"> <div className="md:w-1/4"> diff --git a/app/components/form/TextField.tsx b/app/components/form/TextField.tsx index f4014e0..1e28df5 100644 --- a/app/components/form/TextField.tsx +++ b/app/components/form/TextField.tsx @@ -1,9 +1,9 @@ import React from 'react' import { SyntheticEvent } from 'react' -interface TextFieldProps { +interface TextFieldProps extends React.HTMLAttributes<any> { fieldName: string; - fieldSetter: Function; + fieldSetter: React.Dispatch<React.SetStateAction<string>>; } export default function TextField({fieldName, fieldSetter}: TextFieldProps) { diff --git a/app/profiles/edit/[id]/page.tsx b/app/profiles/edit/[id]/page.tsx index 9fd0f32..87f7bd0 100644 --- a/app/profiles/edit/[id]/page.tsx +++ b/app/profiles/edit/[id]/page.tsx @@ -4,6 +4,9 @@ import { useRouter } from 'next/navigation' import { fetcher } from '@/app/lib' import useSWR from 'swr' +import LabelAndTextField from '@/app/components/form/LabelAndTextField'; +import Submit from '@/app/components/form/Submit'; + export default function ProfileEdit({params} :{params:{id:number}}) { const router = useRouter() const [name, setName] = useState<string>(''); @@ -20,7 +23,7 @@ export default function ProfileEdit({params} :{params:{id:number}}) { const [shockHsr, setShockHsr] = useState<string>(''); const [shockLsr, setShockLsr] = useState<string>(''); - const {data : profile,isLoading, error} = useSWR(`/api/profiles/${params.id}`,fetcher) + const {data : profile, isLoading, error} = useSWR(`/api/profiles/${params.id}`,fetcher) useEffect(()=>{ if(profile){ setName(profile.name) @@ -66,155 +69,32 @@ export default function ProfileEdit({params} :{params:{id:number}}) { const content = await res.json(); if(content.success>0) { - router.push('/profile'); + router.push('/profiles'); } } }; if(isLoading) return <div><span>Loading...</span></div> if (!profile) return null; - const labelClassNames = 'block text-gray-500 font-bold md:text-right mb-1 md:mb-0 pr-4'; - const inputClassNames = 'bg-gray-200 appearance-none border-2 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-blue-500'; return ( <form className="w-full bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4" onSubmit={updateProfile}> <h1 className="text-xl font-bold">Edit profile</h1> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="name"> - Name - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="name" type="text" value={name} onChange={(e:any)=>setName(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="forkPsi"> - Fork PSI - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="forkPsi" type="text" value={forkPsi} onChange={(e:any)=>setForkPsi(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="forkSag"> - Fork sag - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="forkSag" type="text" value={forkSag} onChange={(e:any)=>setForkSag(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="forkHsc"> - Fork HSC - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="forkHsc" type="text" value={forkHsc} onChange={(e:any)=>seForkHsc(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="forkLsc"> - Fork LSC - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="forkLsc" type="text" value={forkLsc} onChange={(e:any)=>setForkLsc(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="forkHsr"> - Fork HSR - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="forkHsr" type="text" value={forkHsr} onChange={(e:any)=>setForkHsr(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="forkLsr"> - Fork LSR - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="forkLsr" type="text" value={forkLsr} onChange={(e:any)=>setForkLsr(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="shockPsi"> - Shock PSI - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="shockPsi" type="text" value={shockPsi} onChange={(e:any)=>setShockPsi(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="shockSag"> - Shock sag - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="shockSag" type="text" value={shockSag} onChange={(e:any)=>setShockSag(e.target.value)}/> - </div> - </div> - - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="shockHsc"> - Shock HSC - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="shockHsc" type="text" value={shockHsc} onChange={(e:any)=>setShockHsc(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="shockLsc"> - Shock LSC - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="shockLsc" type="text" value={shockLsc} onChange={(e:any)=>setShockLsc(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="shockHsr"> - Shock HSR - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="shockHsr" type="text" value={shockHsr} onChange={(e:any)=>setShockHsr(e.target.value)}/> - </div> - </div> - <div className="md:flex md:items-center mb-6"> - <div className="md:w-1/3"> - <label className={labelClassNames} htmlFor="shockLsr"> - Shock LSR - </label> - </div> - <div className="md:w-2/3"> - <input className={inputClassNames} id="shockLsr" type="text" value={shockLsr} onChange={(e:any)=>setShockLsr(e.target.value)}/> - </div> - </div> + <LabelAndTextField fieldName={'name'} fieldSetter={setName} labelText={'Name'} /> + <LabelAndTextField fieldName={'forkPsi'} fieldSetter={setForkPsi} labelText={'Fork PSI'} /> + <LabelAndTextField fieldName={'forkSag'} fieldSetter={setForkSag} labelText={'Fork sag'} /> + <LabelAndTextField fieldName={'forkHsc'} fieldSetter={setForkHsc} labelText={'Fork HSC'} /> + <LabelAndTextField fieldName={'forkLsc'} fieldSetter={setForkLsc} labelText={'Fork LSC'} /> + <LabelAndTextField fieldName={'forkHsr'} fieldSetter={setForkHsr} labelText={'Fork HSR'} /> + <LabelAndTextField fieldName={'forkLsr'} fieldSetter={setForkLsr} labelText={'Fork LSR'} /> + <LabelAndTextField fieldName={'shockPsi'} fieldSetter={setShockPsi} labelText={'Shock PSI'} /> + <LabelAndTextField fieldName={'shockSag'} fieldSetter={setShockSag} labelText={'Shock sag'} /> + <LabelAndTextField fieldName={'shockHsc'} fieldSetter={setShockHsc} labelText={'Shock HSC'} /> + <LabelAndTextField fieldName={'shockLsc'} fieldSetter={setShockLsc} labelText={'Shock LSC'} /> + <LabelAndTextField fieldName={'shockHsr'} fieldSetter={setShockHsr} labelText={'Shock HSR'} /> + <LabelAndTextField fieldName={'shockLsr'} fieldSetter={setShockLsr} labelText={'Shock LSR'} /> - <div className='w-full py-2'> - <button className="w-20 p-2 text-white border-gray-200 border-[1px] rounded-sm bg-green-400">Submit</button> - </div> + <Submit /> </form> ) } - diff --git a/app/profiles/page.tsx b/app/profiles/page.tsx index 185f557..7f138d3 100644 --- a/app/profiles/page.tsx +++ b/app/profiles/page.tsx @@ -18,20 +18,7 @@ export default function Profiles() { if (error) return <div>Failed to load</div>; if (isLoading) return <div>Loading...</div>; if (!data) return null; - let delete_Profile : ProfileModel['deleteProfile']= async (id:number) => { - const res = await fetch(`/api/profiles/${id}`, { - method: 'DELETE', - headers: { - 'Content-Type': 'application/json' - }, - }); - const content = await res.json(); - if(content.success>0) - { - setProfiles(profiles?.filter((profile:ProfileModel)=>{ return profile.id !== id })); - } - } return ( <div className="w-full max-w-7xl m-auto"> <table className="w-full border-collapse border border-slate-400"> @@ -47,7 +34,7 @@ export default function Profiles() { </thead> <tbody> { - profiles && profiles.map((item : ProfileModel)=><Profile key={item.id} {...item} deleteProfile = {delete_Profile} />) + profiles && profiles.map((item : ProfileModel)=><Profile key={item.id} {...item} />) } <tr> <td colSpan={6}> @@ -59,4 +46,3 @@ export default function Profiles() { </div> ); } - diff --git a/index.tsx b/index.tsx index c880492..f6f79f5 100644 --- a/index.tsx +++ b/index.tsx @@ -1,8 +1,5 @@ -import { Link } from 'components'; - -export default Home; - -function Home() { +import Link from "next/link"; +export default function Home() { return ( <div> <h1>Next.js 10 - CRUD Example with React Hook Form</h1> From 99cf4f21486f6f92985f78080e8b690e5a2e90b8 Mon Sep 17 00:00:00 2001 From: Steve Laing <steve.laing@gmail.com> Date: Wed, 21 Feb 2024 11:12:00 +0000 Subject: [PATCH 14/21] Use API to delete profiles --- app/components/Profile.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/Profile.tsx b/app/components/Profile.tsx index 2181217..08d9cee 100644 --- a/app/components/Profile.tsx +++ b/app/components/Profile.tsx @@ -13,7 +13,7 @@ export default function Profile(params: ProfileModel) { <td className='border border-slate-300'>{params.shockSag}%</td> <td className='w-52 border border-slate-300'> <Link href={`/profiles/edit/${params.id}`} className='bg-yellow-500 p-2 inline-block text-white text-sm'>Edit</Link> - <span onClick={()=>params.deleteProfile(params.id)} className='bg-red-500 ml-3 p-2 inline-block text-white text-sm'>Delete</span> + <Link href={`/profiles/delete/${params.id}`} className='bg-red-500 ml-3 p-2 inline-block text-white text-sm'>Delete</Link> </td> </tr> ) From 604744ec3811928cf9e0427a9b6438e67ab62b6e Mon Sep 17 00:00:00 2001 From: Steve Laing <steve.laing@gmail.com> Date: Wed, 21 Feb 2024 11:12:26 +0000 Subject: [PATCH 15/21] Add success to API responses --- pages/api/profiles.ts | 6 +++--- pages/api/profiles/[id].ts | 4 ++-- pages/api/profilesRepo.js | 7 ++++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pages/api/profiles.ts b/pages/api/profiles.ts index 9d9d555..47bd927 100644 --- a/pages/api/profiles.ts +++ b/pages/api/profiles.ts @@ -8,13 +8,13 @@ export default function handler( ) { const getProfiles = () => { const profiles = profilesRepo.getAll(); - return res.status(200).json(profiles); + return res.status(200).json({profiles: profiles, success: 1}); } const createProfile = () => { try { - profilesRepo.create(req.body); - return res.status(200).json({}); + const profile = profilesRepo.create(req.body); + return res.status(200).json({success:1, id: profile.id}); } catch (error: any) { return res.status(400).json({ message: error }); } diff --git a/pages/api/profiles/[id].ts b/pages/api/profiles/[id].ts index b0bc5f8..ee73afb 100644 --- a/pages/api/profiles/[id].ts +++ b/pages/api/profiles/[id].ts @@ -15,7 +15,7 @@ export default function handler( const updateProfile = () => { try { profilesRepo.update(req.query.id, req.body); - return res.status(200).json({}); + return res.status(200).json({success:1}); } catch (error) { return res.status(400).json({ message: error }); } @@ -23,7 +23,7 @@ export default function handler( const deleteProfile = () => { profilesRepo.delete(req.query.id); - return res.status(200).json({}); + return res.status(200).json({success:1}); } switch (req.method) { diff --git a/pages/api/profilesRepo.js b/pages/api/profilesRepo.js index ccf82b1..63014ca 100644 --- a/pages/api/profilesRepo.js +++ b/pages/api/profilesRepo.js @@ -11,7 +11,10 @@ const getById = (id) => { } const create = ({ name, forkPsi, forkSag, forkHsc, forkLsc, forkHsr, forkLsr, shockPsi, shockSag, shockHsc, shockLsc, shockHsr, shockLsr }) => { - const profile = { name, forkPsi, forkSag, forkHsc, forkLsc, forkHsr, forkLsr, shockPsi, shockSag, shockHsc, shockLsc, shockHsr, shockLsr }; + const profile = { + id, name, forkPsi, forkSag, forkHsc, forkLsc, forkHsr, forkLsr, + shockPsi, shockSag, shockHsc, shockLsc, shockHsr, shockLsr + }; // validate if (profiles.find(x => x.name === profile.name)) @@ -27,6 +30,8 @@ const create = ({ name, forkPsi, forkSag, forkHsc, forkLsc, forkHsr, forkLsr, sh // add and save profile profiles.push(profile); saveData(); + + return profile; } const update = (id, { name, forkPsi, forkSag, forkHsc, forkLsc, forkHsr, forkLsr, shockPsi, shockSag, shockHsc, shockLsc, shockHsr, shockLsr }) => { From 63fb7b7eeade9fb4680c2aade0ef6f50616e3863 Mon Sep 17 00:00:00 2001 From: Steve Laing <steve.laing@gmail.com> Date: Wed, 21 Feb 2024 11:13:02 +0000 Subject: [PATCH 16/21] Add delete action --- app/profiles/delete/[id]/page.tsx | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 app/profiles/delete/[id]/page.tsx diff --git a/app/profiles/delete/[id]/page.tsx b/app/profiles/delete/[id]/page.tsx new file mode 100644 index 0000000..6021f4e --- /dev/null +++ b/app/profiles/delete/[id]/page.tsx @@ -0,0 +1,49 @@ +"use client" +import React, {useState,useEffect } from 'react' +import { useRouter } from 'next/navigation' +import { fetcher } from '@/app/lib' +import useSWR from 'swr' + +export default function ProfileDelete({params} :{params:{id:number}}) { + const router = useRouter() + const [name, setName] = useState<string>(''); + const {data : profile,isLoading, error} = useSWR(`/api/profiles/${params.id}`,fetcher) + + useEffect(()=>{ + if (profile) { + setName(profile.name); + } + },[profile, isLoading]) + + const deleteProfile = async (e: any) => { + e.preventDefault() + const res = await fetch(`/api/profiles/${params.id}`, { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json' + }, + }); + const content = await res.json(); + if(content.success > 0) + { + router.push('/profiles'); + } + }; + + if (isLoading) return <div><span>Loading...</span></div> + if (!profile) return null; + + const labelClassNames = 'block text-gray-500 font-bold md:text-right mb-1 md:mb-0 pr-4'; + const inputClassNames = 'bg-gray-200 appearance-none border-2 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-blue-500'; + + return ( + <form className="w-full bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4" onSubmit={deleteProfile}> + <h1 className="text-xl font-bold">Are you sure you want to delete suspension profile {profile.name}?</h1> + + <div className='w-full py-2'> + <button className="w-20 p-2 text-white border-gray-200 border-[1px] rounded-sm bg-red-400">Delete</button> + </div> + </form> + ) +} + From 052014184c6cdec4dd1e6290e7f90b6440ae6637 Mon Sep 17 00:00:00 2001 From: Steve Laing <steve.laing@gmail.com> Date: Wed, 21 Feb 2024 11:13:28 +0000 Subject: [PATCH 17/21] Read success attribute from API response --- app/profiles/create/page.tsx | 2 +- app/profiles/page.tsx | 15 ++++++++------- app/profiles/read/[id]/page.tsx | 5 +++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/profiles/create/page.tsx b/app/profiles/create/page.tsx index 4142d6f..e36774b 100644 --- a/app/profiles/create/page.tsx +++ b/app/profiles/create/page.tsx @@ -47,7 +47,7 @@ export default function ProfileCreate() { }); const content = await add.json(); if(content.success > 0) { - router.push(`/profiles/read/${content.id}`); + router.push(`/profiles/read/${content.profile.id}`); } } }; diff --git a/app/profiles/page.tsx b/app/profiles/page.tsx index 7f138d3..d30f257 100644 --- a/app/profiles/page.tsx +++ b/app/profiles/page.tsx @@ -7,18 +7,19 @@ import { ProfileModel } from "../types"; import Link from "next/link"; export default function Profiles() { - const [profiles,setProfiles] = useState<ProfileModel[]>([]); + const [profiles, setProfiles] = useState<ProfileModel[]>([]); const { data, error, isLoading } = useSWR<any>(`/api/profiles`, fetcher); - useEffect(()=>{ - if(data) - { - setProfiles(data); + + useEffect(() => { + if (data) { + setProfiles(data.profiles); } - },[data,isLoading]); + }, [data,isLoading]); + if (error) return <div>Failed to load</div>; if (isLoading) return <div>Loading...</div>; if (!data) return null; - + return ( <div className="w-full max-w-7xl m-auto"> <table className="w-full border-collapse border border-slate-400"> diff --git a/app/profiles/read/[id]/page.tsx b/app/profiles/read/[id]/page.tsx index 311552c..ccd82db 100644 --- a/app/profiles/read/[id]/page.tsx +++ b/app/profiles/read/[id]/page.tsx @@ -3,9 +3,10 @@ import { fetcher } from '@/app/lib' import useSWR from 'swr' export default function Detail({params}: {params:{id :number}}) { - const {data: profile, isLoading, error} = useSWR(`/api/profiles/${params.id}`,fetcher) + const {data: data, isLoading, error} = useSWR(`/api/profiles/${params.id}`,fetcher) if(isLoading) return <div><span>Loading...</span></div> - if (!profile) return null; + if (!data || !data.profile) return null; + const profile = data.profile; return ( <div className='w-full'> <h2 className='text-center font-bold text-3xl py-3'>{profile.name}</h2> From fe76bdc4c99fb776d5565d93b2255938e3d18916 Mon Sep 17 00:00:00 2001 From: Steve Laing <steve.laing@gmail.com> Date: Wed, 21 Feb 2024 13:17:53 +0000 Subject: [PATCH 18/21] Add fieldValue attribute --- app/components/form/LabelAndTextField.tsx | 6 +++--- app/components/form/TextField.tsx | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/components/form/LabelAndTextField.tsx b/app/components/form/LabelAndTextField.tsx index fc2ac35..eb6394f 100644 --- a/app/components/form/LabelAndTextField.tsx +++ b/app/components/form/LabelAndTextField.tsx @@ -1,22 +1,22 @@ import React from 'react' -import { SyntheticEvent } from 'react' import Label from './Label' import TextField from './TextField' interface LabelAndTextFieldProps extends React.HTMLAttributes<any> { fieldName: string; + fieldValue: string; fieldSetter: React.Dispatch<React.SetStateAction<string>>; labelText: string; } -export default function LabelAndTextField({fieldName, fieldSetter, labelText}: LabelAndTextFieldProps) { +export default function LabelAndTextField({fieldName, fieldValue, fieldSetter, labelText}: LabelAndTextFieldProps) { return ( <div className="md:flex md:items-center mb-6"> <div className="md:w-1/4"> <Label fieldName={fieldName} labelText={labelText} /> </div> <div className="md:w-2/4"> - <TextField fieldName={fieldName} fieldSetter={fieldSetter} /> + <TextField fieldName={fieldName} fieldSetter={fieldSetter} fieldValue={fieldValue} /> </div> </div> ) diff --git a/app/components/form/TextField.tsx b/app/components/form/TextField.tsx index 1e28df5..30b2e4e 100644 --- a/app/components/form/TextField.tsx +++ b/app/components/form/TextField.tsx @@ -3,10 +3,11 @@ import { SyntheticEvent } from 'react' interface TextFieldProps extends React.HTMLAttributes<any> { fieldName: string; + fieldValue: string; fieldSetter: React.Dispatch<React.SetStateAction<string>>; } -export default function TextField({fieldName, fieldSetter}: TextFieldProps) { +export default function TextField({fieldName, fieldValue, fieldSetter}: TextFieldProps) { const classNames = 'bg-gray-200 appearance-none border-2 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-blue-500'; const onChange = (e: React.ChangeEvent<HTMLInputElement>): void => { @@ -14,6 +15,6 @@ export default function TextField({fieldName, fieldSetter}: TextFieldProps) { } return ( - <input className={classNames} id={fieldName} type="text" onChange={onChange}/> + <input className={classNames} id={fieldName} value={fieldValue} type="text" onChange={onChange}/> ) } From 4bf1ad05cedd032a8047e311e3e7ca387af1478e Mon Sep 17 00:00:00 2001 From: Steve Laing <steve.laing@gmail.com> Date: Wed, 21 Feb 2024 13:20:21 +0000 Subject: [PATCH 19/21] Populate fieldValue attribute on edit --- app/profiles/create/page.tsx | 27 +++++++------- app/profiles/edit/[id]/page.tsx | 64 +++++++++++++++++---------------- 2 files changed, 46 insertions(+), 45 deletions(-) diff --git a/app/profiles/create/page.tsx b/app/profiles/create/page.tsx index e36774b..d73edaa 100644 --- a/app/profiles/create/page.tsx +++ b/app/profiles/create/page.tsx @@ -58,20 +58,19 @@ export default function ProfileCreate() { <div className="m-auto w-full text-center mb-10"> <h1 className="text-xl font-bold">Add a new suspension profile</h1> </div> - - <LabelAndTextField fieldName={'name'} fieldSetter={setName} labelText={'Name'} /> - <LabelAndTextField fieldName={'forkPsi'} fieldSetter={setForkPsi} labelText={'Fork PSI'} /> - <LabelAndTextField fieldName={'forkSag'} fieldSetter={setForkSag} labelText={'Fork sag'} /> - <LabelAndTextField fieldName={'forkHsc'} fieldSetter={setForkHsc} labelText={'Fork HSC'} /> - <LabelAndTextField fieldName={'forkLsc'} fieldSetter={setForkLsc} labelText={'Fork LSC'} /> - <LabelAndTextField fieldName={'forkHsr'} fieldSetter={setForkHsr} labelText={'Fork HSR'} /> - <LabelAndTextField fieldName={'forkLsr'} fieldSetter={setForkLsr} labelText={'Fork LSR'} /> - <LabelAndTextField fieldName={'shockPsi'} fieldSetter={setShockPsi} labelText={'Shock PSI'} /> - <LabelAndTextField fieldName={'shockSag'} fieldSetter={setShockSag} labelText={'Shock sag'} /> - <LabelAndTextField fieldName={'shockHsc'} fieldSetter={setShockHsc} labelText={'Shock HSC'} /> - <LabelAndTextField fieldName={'shockLsc'} fieldSetter={setShockLsc} labelText={'Shock LSC'} /> - <LabelAndTextField fieldName={'shockHsr'} fieldSetter={setShockHsr} labelText={'Shock HSR'} /> - <LabelAndTextField fieldName={'shockLsr'} fieldSetter={setShockLsr} labelText={'Shock LSR'} /> + <LabelAndTextField fieldName={'name'} fieldValue={name} fieldSetter={setName} labelText={'Name'} /> + <LabelAndTextField fieldName={'forkPsi'} fieldValue={forkPsi} fieldSetter={setForkPsi} labelText={'Fork PSI'} /> + <LabelAndTextField fieldName={'forkSag'} fieldValue={forkSag} fieldSetter={setForkSag} labelText={'Fork sag'} /> + <LabelAndTextField fieldName={'forkHsc'} fieldValue={forkHsc} fieldSetter={setForkHsc} labelText={'Fork HSC'} /> + <LabelAndTextField fieldName={'forkLsc'} fieldValue={forkLsc} fieldSetter={setForkLsc} labelText={'Fork LSC'} /> + <LabelAndTextField fieldName={'forkHsr'} fieldValue={forkHsr} fieldSetter={setForkHsr} labelText={'Fork HSR'} /> + <LabelAndTextField fieldName={'forkLsr'} fieldValue={forkLsr} fieldSetter={setForkLsr} labelText={'Fork LSR'} /> + <LabelAndTextField fieldName={'shockPsi'} fieldValue={shockPsi} fieldSetter={setShockPsi} labelText={'Shock PSI'} /> + <LabelAndTextField fieldName={'shockSag'} fieldValue={shockSag} fieldSetter={setShockSag} labelText={'Shock sag'} /> + <LabelAndTextField fieldName={'shockHsc'} fieldValue={shockHsc} fieldSetter={setShockHsc} labelText={'Shock HSC'} /> + <LabelAndTextField fieldName={'shockLsc'} fieldValue={shockLsc} fieldSetter={setShockLsc} labelText={'Shock LSC'} /> + <LabelAndTextField fieldName={'shockHsr'} fieldValue={shockHsr} fieldSetter={setShockHsr} labelText={'Shock HSR'} /> + <LabelAndTextField fieldName={'shockLsr'} fieldValue={shockLsr} fieldSetter={setShockLsr} labelText={'Shock LSR'} /> <Submit /> </form> diff --git a/app/profiles/edit/[id]/page.tsx b/app/profiles/edit/[id]/page.tsx index 87f7bd0..549573c 100644 --- a/app/profiles/edit/[id]/page.tsx +++ b/app/profiles/edit/[id]/page.tsx @@ -8,7 +8,7 @@ import LabelAndTextField from '@/app/components/form/LabelAndTextField'; import Submit from '@/app/components/form/Submit'; export default function ProfileEdit({params} :{params:{id:number}}) { - const router = useRouter() + const router = useRouter(); const [name, setName] = useState<string>(''); const [forkPsi, setForkPsi] = useState<string>(''); const [forkSag, setForkSag] = useState<string>(''); @@ -23,24 +23,26 @@ export default function ProfileEdit({params} :{params:{id:number}}) { const [shockHsr, setShockHsr] = useState<string>(''); const [shockLsr, setShockLsr] = useState<string>(''); - const {data : profile, isLoading, error} = useSWR(`/api/profiles/${params.id}`,fetcher) + const {data: profile, isLoading, error} = useSWR(`/api/profiles/${params.id}`,fetcher); + useEffect(()=>{ - if(profile){ - setName(profile.name) - setForkPsi(profile.forkPsi) - setForkSag(profile.forkSag) - setForkHsc(profile.forkHsc) - setForkLsc(profile.forkLsc) - setForkHsr(profile.forkHsr) - setForkLsr(profile.forkLsr) - setShockPsi(profile.shockPsi) - setShockSag(profile.shockSag) - setShockHsc(profile.shockHsc) - setShockLsc(profile.shockLsc) - setShockHsr(profile.shockHsr) - setShockLsr(profile.shockLsr) - } + if (profile){ + setName(profile.name) + setForkPsi(profile.forkPsi) + setForkSag(profile.forkSag) + setForkHsc(profile.forkHsc) + setForkLsc(profile.forkLsc) + setForkHsr(profile.forkHsr) + setForkLsr(profile.forkLsr) + setShockPsi(profile.shockPsi) + setShockSag(profile.shockSag) + setShockHsc(profile.shockHsc) + setShockLsc(profile.shockLsc) + setShockHsr(profile.shockHsr) + setShockLsr(profile.shockLsr) + } },[profile, isLoading]) + const updateProfile = async (e: any) => { e.preventDefault() if (name != "" && forkPsi != "" && shockPsi != "") { @@ -67,7 +69,7 @@ export default function ProfileEdit({params} :{params:{id:number}}) { body: JSON.stringify(formData) }); const content = await res.json(); - if(content.success>0) + if(content.success > 0) { router.push('/profiles'); } @@ -80,19 +82,19 @@ export default function ProfileEdit({params} :{params:{id:number}}) { return ( <form className="w-full bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4" onSubmit={updateProfile}> <h1 className="text-xl font-bold">Edit profile</h1> - <LabelAndTextField fieldName={'name'} fieldSetter={setName} labelText={'Name'} /> - <LabelAndTextField fieldName={'forkPsi'} fieldSetter={setForkPsi} labelText={'Fork PSI'} /> - <LabelAndTextField fieldName={'forkSag'} fieldSetter={setForkSag} labelText={'Fork sag'} /> - <LabelAndTextField fieldName={'forkHsc'} fieldSetter={setForkHsc} labelText={'Fork HSC'} /> - <LabelAndTextField fieldName={'forkLsc'} fieldSetter={setForkLsc} labelText={'Fork LSC'} /> - <LabelAndTextField fieldName={'forkHsr'} fieldSetter={setForkHsr} labelText={'Fork HSR'} /> - <LabelAndTextField fieldName={'forkLsr'} fieldSetter={setForkLsr} labelText={'Fork LSR'} /> - <LabelAndTextField fieldName={'shockPsi'} fieldSetter={setShockPsi} labelText={'Shock PSI'} /> - <LabelAndTextField fieldName={'shockSag'} fieldSetter={setShockSag} labelText={'Shock sag'} /> - <LabelAndTextField fieldName={'shockHsc'} fieldSetter={setShockHsc} labelText={'Shock HSC'} /> - <LabelAndTextField fieldName={'shockLsc'} fieldSetter={setShockLsc} labelText={'Shock LSC'} /> - <LabelAndTextField fieldName={'shockHsr'} fieldSetter={setShockHsr} labelText={'Shock HSR'} /> - <LabelAndTextField fieldName={'shockLsr'} fieldSetter={setShockLsr} labelText={'Shock LSR'} /> + <LabelAndTextField fieldName={'name'} fieldValue={name} fieldSetter={setName} labelText={'Name'} /> + <LabelAndTextField fieldName={'forkPsi'} fieldValue={forkPsi} fieldSetter={setForkPsi} labelText={'Fork PSI'} /> + <LabelAndTextField fieldName={'forkSag'} fieldValue={forkSag} fieldSetter={setForkSag} labelText={'Fork sag'} /> + <LabelAndTextField fieldName={'forkHsc'} fieldValue={forkHsc} fieldSetter={setForkHsc} labelText={'Fork HSC'} /> + <LabelAndTextField fieldName={'forkLsc'} fieldValue={forkLsc} fieldSetter={setForkLsc} labelText={'Fork LSC'} /> + <LabelAndTextField fieldName={'forkHsr'} fieldValue={forkHsr} fieldSetter={setForkHsr} labelText={'Fork HSR'} /> + <LabelAndTextField fieldName={'forkLsr'} fieldValue={forkLsr} fieldSetter={setForkLsr} labelText={'Fork LSR'} /> + <LabelAndTextField fieldName={'shockPsi'} fieldValue={shockPsi} fieldSetter={setShockPsi} labelText={'Shock PSI'} /> + <LabelAndTextField fieldName={'shockSag'} fieldValue={shockSag} fieldSetter={setShockSag} labelText={'Shock sag'} /> + <LabelAndTextField fieldName={'shockHsc'} fieldValue={shockHsc} fieldSetter={setShockHsc} labelText={'Shock HSC'} /> + <LabelAndTextField fieldName={'shockLsc'} fieldValue={shockLsc} fieldSetter={setShockLsc} labelText={'Shock LSC'} /> + <LabelAndTextField fieldName={'shockHsr'} fieldValue={shockHsr} fieldSetter={setShockHsr} labelText={'Shock HSR'} /> + <LabelAndTextField fieldName={'shockLsr'} fieldValue={shockLsr} fieldSetter={setShockLsr} labelText={'Shock LSR'} /> <Submit /> </form> From 4e22d1138eb801d34d5fc1546f6984c3109ebebf Mon Sep 17 00:00:00 2001 From: Steve Laing <steve.laing@gmail.com> Date: Wed, 21 Feb 2024 13:20:49 +0000 Subject: [PATCH 20/21] Fix imports and metadata --- app/layout.tsx | 8 ++++---- app/page.tsx | 2 +- app/profiles/create/page.tsx | 4 ++-- app/profiles/page.tsx | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/layout.tsx b/app/layout.tsx index badec46..7759301 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,13 +1,13 @@ -import './globals.css' +import '@/app/globals.css' import type { Metadata } from 'next' import { Inter } from 'next/font/google' -import Header from './components/Header' +import Header from '@/app/components/Header' const inter = Inter({ subsets: ['latin'] }) export const metadata: Metadata = { - title: 'Create Next App', - description: 'Generated by create next app', + title: 'Suspense', + description: 'Record your suspension settings', } export default function RootLayout({ diff --git a/app/page.tsx b/app/page.tsx index 209125c..e6dfef2 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,4 +1,4 @@ -import Profiles from './profiles/page' +import Profiles from '@/app/profiles/page' export default function Home() { return ( <Profiles /> diff --git a/app/profiles/create/page.tsx b/app/profiles/create/page.tsx index d73edaa..7893c8f 100644 --- a/app/profiles/create/page.tsx +++ b/app/profiles/create/page.tsx @@ -1,8 +1,8 @@ "use client" import React, {useState } from 'react' import { useRouter } from 'next/navigation' -import LabelAndTextField from '../../components/form/LabelAndTextField' -import Submit from '../../components/form/Submit' +import LabelAndTextField from '@/app/components/form/LabelAndTextField' +import Submit from '@/app/components/form/Submit' export default function ProfileCreate() { const router = useRouter() diff --git a/app/profiles/page.tsx b/app/profiles/page.tsx index d30f257..8cdb752 100644 --- a/app/profiles/page.tsx +++ b/app/profiles/page.tsx @@ -1,9 +1,9 @@ "use client"; import React,{useEffect, useState} from "react"; import useSWR from "swr"; -import { fetcher } from "../lib"; -import Profile from "../components/Profile"; -import { ProfileModel } from "../types"; +import { fetcher } from "@/app/lib"; +import Profile from "@/app/components/Profile"; +import { ProfileModel } from "@/app/types"; import Link from "next/link"; export default function Profiles() { From 66494b64461467e3c8a76c8186ef259dd086b27e Mon Sep 17 00:00:00 2001 From: Steve Laing <steve.laing@gmail.com> Date: Thu, 22 Feb 2024 16:57:52 +0000 Subject: [PATCH 21/21] Convert profilesRepo to typescript --- app/types/index.ts | 2 ++ pages/api/profiles/[id].ts | 6 ++-- .../api/{profilesRepo.js => profilesRepo.ts} | 29 +++++++++---------- 3 files changed, 19 insertions(+), 18 deletions(-) rename pages/api/{profilesRepo.js => profilesRepo.ts} (60%) diff --git a/app/types/index.ts b/app/types/index.ts index dad1eef..5a61277 100644 --- a/app/types/index.ts +++ b/app/types/index.ts @@ -13,4 +13,6 @@ export interface ProfileModel { shockHsr: number, shockLsr: number, shockSag: number, + dateCreated: string, + dateUpdated: string } diff --git a/pages/api/profiles/[id].ts b/pages/api/profiles/[id].ts index ee73afb..65ea7e4 100644 --- a/pages/api/profiles/[id].ts +++ b/pages/api/profiles/[id].ts @@ -8,13 +8,13 @@ export default function handler( ) { const getProfileById = () => { - const profile = profilesRepo.getById(req.query.id); + const profile = profilesRepo.getById(Number(req.query.id)); return res.status(200).json(profile); } const updateProfile = () => { try { - profilesRepo.update(req.query.id, req.body); + profilesRepo.update(Number(req.query.id), req.body); return res.status(200).json({success:1}); } catch (error) { return res.status(400).json({ message: error }); @@ -22,7 +22,7 @@ export default function handler( } const deleteProfile = () => { - profilesRepo.delete(req.query.id); + profilesRepo.delete(Number(req.query.id)); return res.status(200).json({success:1}); } diff --git a/pages/api/profilesRepo.js b/pages/api/profilesRepo.ts similarity index 60% rename from pages/api/profilesRepo.js rename to pages/api/profilesRepo.ts index 63014ca..b2aecc0 100644 --- a/pages/api/profilesRepo.js +++ b/pages/api/profilesRepo.ts @@ -1,28 +1,27 @@ const fs = require('fs'); - -let profiles = require('./../../data/profiles.json'); +import { ProfileModel } from '@/app/types/index'; +let profiles = require('@/data/profiles.json'); const getAll = () => { return profiles; } -const getById = (id) => { - return profiles.find(x => x.id.toString() === id.toString()); +const getById = (id:number) => { + return profiles.find((x:ProfileModel) => x.id.toString() === id.toString()); } -const create = ({ name, forkPsi, forkSag, forkHsc, forkLsc, forkHsr, forkLsr, shockPsi, shockSag, shockHsc, shockLsc, shockHsr, shockLsr }) => { - const profile = { +const create = ({ name, forkPsi, forkSag, forkHsc, forkLsc, forkHsr, forkLsr, shockPsi, shockSag, shockHsc, shockLsc, shockHsr, shockLsr }:ProfileModel) => { + const id:number = profiles.length ? Math.max(...profiles.map((x:ProfileModel) => x.id)) + 1 : 1; + + const profile = <ProfileModel>{ id, name, forkPsi, forkSag, forkHsc, forkLsc, forkHsr, forkLsr, shockPsi, shockSag, shockHsc, shockLsc, shockHsr, shockLsr }; // validate - if (profiles.find(x => x.name === profile.name)) + if (profiles.find((x:ProfileModel) => x.name === profile.name)) throw `Profile with the name ${profile.name} already exists`; - // generate new profile id - profile.id = profiles.length ? Math.max(...profiles.map(x => x.id)) + 1 : 1; - // set date created and updated profile.dateCreated = new Date().toISOString(); profile.dateUpdated = new Date().toISOString(); @@ -34,12 +33,12 @@ const create = ({ name, forkPsi, forkSag, forkHsc, forkLsc, forkHsr, forkLsr, sh return profile; } -const update = (id, { name, forkPsi, forkSag, forkHsc, forkLsc, forkHsr, forkLsr, shockPsi, shockSag, shockHsc, shockLsc, shockHsr, shockLsr }) => { +const update = (id:number, { name, forkPsi, forkSag, forkHsc, forkLsc, forkHsr, forkLsr, shockPsi, shockSag, shockHsc, shockLsc, shockHsr, shockLsr }:ProfileModel) => { const params = { name, forkPsi, forkSag, forkHsc, forkLsc, forkHsr, forkLsr, shockPsi, shockSag, shockHsc, shockLsc, shockHsr, shockLsr }; - const profile = profiles.find(x => x.id.toString() === id.toString()); + const profile = profiles.find((x:ProfileModel) => x.id.toString() === id.toString()); // validate - if (params.name !== profile.name && profiles.find(x => x.name === params.name)) + if (params.name !== profile.name && profiles.find((x:ProfileModel) => x.name === params.name)) throw `Profile with the name ${params.name} already exists`; // set date updated @@ -51,9 +50,9 @@ const update = (id, { name, forkPsi, forkSag, forkHsc, forkLsc, forkHsr, forkLsr } // prefixed with underscore '_' because 'delete' is a reserved word in javascript -const _delete = (id) => { +const _delete = (id:number) => { // filter out deleted profile and save - profiles = profiles.filter(x => x.id.toString() !== id.toString()); + profiles = profiles.filter((x:ProfileModel) => x.id.toString() !== id.toString()); saveData(); }