From b94772bfcd530eacbe1cd7494bf969d9ee8e3a89 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 21 Nov 2020 16:11:40 -0500 Subject: [PATCH] begins typing admin, fixes editorconfig --- .editorconfig | 2 +- demo/server.js | 4 +- package.json | 3 +- src/admin/api.tsx | 11 ++- .../views/collections/Edit/Auth/index.tsx | 74 +++++++++--------- src/admin/index.tsx | 75 +++++++++---------- .../{getOffsetTop.tsx => getOffsetTop.ts} | 4 +- src/index.ts | 2 +- yarn.lock | 54 +++++++++++-- 9 files changed, 132 insertions(+), 97 deletions(-) rename src/admin/utilities/{getOffsetTop.tsx => getOffsetTop.ts} (72%) diff --git a/.editorconfig b/.editorconfig index d4e6ee36ed..9a8c81c9b5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,7 +4,7 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[*.{js,ts}] +[*.{js,ts,tsx}] indent_style = space indent_size = 2 diff --git a/demo/server.js b/demo/server.js index 213ccb94e4..295eb4e9f7 100644 --- a/demo/server.js +++ b/demo/server.js @@ -11,8 +11,8 @@ payload.init({ secret: 'SECRET_KEY', mongoURL: 'mongodb://localhost/payload', express: expressApp, - onInit: () => { - console.log('Payload Demo Initialized'); + onInit: (app) => { + app.logger.info('Payload Demo Initialized'); }, }); diff --git a/package.json b/package.json index 2367cd395a..e566adbb7c 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "@faceless-ui/modal": "^1.0.4", "@faceless-ui/scroll-info": "^1.1.1", "@faceless-ui/window-info": "^1.2.2", - "@typescript-eslint/parser": "^4.8.1", + "@typescript-eslint/parser": "4.0.1", "@udecode/slate-plugins": "^0.64.3", "ajv": "^6.12.6", "async-some": "^1.0.2", @@ -186,6 +186,7 @@ "@types/webpack": "4.41.25", "@types/webpack-bundle-analyzer": "^3.9.0", "@types/webpack-dev-middleware": "^3.7.2", + "@types/webpack-env": "^1.15.3", "@types/webpack-hot-middleware": "^2.25.3", "@typescript-eslint/eslint-plugin": "^4.8.1", "babel-eslint": "^10.0.1", diff --git a/src/admin/api.tsx b/src/admin/api.tsx index 197b3820ba..a55f205398 100644 --- a/src/admin/api.tsx +++ b/src/admin/api.tsx @@ -1,13 +1,12 @@ -/* eslint-disable import/prefer-default-export */ import qs from 'qs'; export const requests = { - get: (url, params) => { - const query = qs.stringify(params, { addQueryPrefix: true, depth: 10 }); + get: (url: string, params: unknown = {}): Promise => { + const query = qs.stringify(params, { addQueryPrefix: true }); return fetch(`${url}${query}`); }, - post: (url, options = {}) => { + post: (url: string, options: RequestInit = { headers: {} }): Promise => { const headers = options && options.headers ? { ...options.headers } : {}; const formattedOptions = { @@ -21,7 +20,7 @@ export const requests = { return fetch(`${url}`, formattedOptions); }, - put: (url, options = {}) => { + put: (url: string, options: RequestInit = { headers: {} }): Promise => { const headers = options && options.headers ? { ...options.headers } : {}; const formattedOptions = { @@ -35,7 +34,7 @@ export const requests = { return fetch(url, formattedOptions); }, - delete: (url, options = {}) => { + delete: (url: string, options: RequestInit = { headers: {} }): Promise => { const headers = options && options.headers ? { ...options.headers } : {}; return fetch(url, { ...options, diff --git a/src/admin/components/views/collections/Edit/Auth/index.tsx b/src/admin/components/views/collections/Edit/Auth/index.tsx index a1a248dcff..e1f2c09428 100644 --- a/src/admin/components/views/collections/Edit/Auth/index.tsx +++ b/src/admin/components/views/collections/Edit/Auth/index.tsx @@ -53,7 +53,7 @@ const Auth = (props) => { } else { toast.error('Successfully unlocked'); } - }, [replaceStatus, serverURL, api, slug, email]); + }, [serverURL, api, slug, email]); return (
@@ -64,33 +64,33 @@ const Auth = (props) => { autoComplete="email" /> {(changingPassword || requirePassword) && ( -
- - - {!requirePassword && ( - - )} -
- )} - {(!changingPassword && !requirePassword) && ( +
+ + + {!requirePassword && ( + )} +
+ )} + {(!changingPassword && !requirePassword) && ( + )} {useAPIKey && ( -
- - {enableAPIKey?.value && ( - - )} -
+
+ + {enableAPIKey?.value && ( + + )} +
)} {verify && ( - + )}
); diff --git a/src/admin/index.tsx b/src/admin/index.tsx index 9c02a34a8e..9eb7fd0d53 100644 --- a/src/admin/index.tsx +++ b/src/admin/index.tsx @@ -14,47 +14,42 @@ import ConfigProvider from './components/providers/Config/Provider'; import './scss/app.scss'; -const Index = () => { - const windowInfoProps = {}; +const Index = () => ( + + + + + + + + + + + + + + + + + + + + + - windowInfoProps.breakpoints = { - xs: parseInt(getCSSVariable('breakpoint-xs-width').replace('px', ''), 10), - s: parseInt(getCSSVariable('breakpoint-s-width').replace('px', ''), 10), - m: parseInt(getCSSVariable('breakpoint-m-width').replace('px', ''), 10), - l: parseInt(getCSSVariable('breakpoint-l-width').replace('px', ''), 10), - }; - - return ( - - - - - - - - - - - - - - - - - - - - - - - ); -}; +); render(, document.getElementById('app')); diff --git a/src/admin/utilities/getOffsetTop.tsx b/src/admin/utilities/getOffsetTop.ts similarity index 72% rename from src/admin/utilities/getOffsetTop.tsx rename to src/admin/utilities/getOffsetTop.ts index 4d58643895..3b09b269f8 100644 --- a/src/admin/utilities/getOffsetTop.tsx +++ b/src/admin/utilities/getOffsetTop.ts @@ -1,4 +1,4 @@ -export default (element) => { +export default (element: HTMLElement): number => { let el = element; // Set our distance placeholder let distance = 0; @@ -7,7 +7,7 @@ export default (element) => { if (el.offsetParent) { do { distance += el.offsetTop; - el = el.offsetParent; + el = el.offsetParent as HTMLElement; } while (el); } diff --git a/src/index.ts b/src/index.ts index 41f08b9198..ea94c2ab8b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -198,7 +198,7 @@ class Payload { this.authenticate = authenticate(this.config); } - if (typeof options.onInit === 'function') options.onInit(); + if (typeof options.onInit === 'function') options.onInit(this); } async sendEmail(message: Message) { diff --git a/yarn.lock b/yarn.lock index c35d64bab7..c07a9e7f06 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2133,6 +2133,11 @@ "@types/webpack" "*" loglevel "^1.6.2" +"@types/webpack-env@^1.15.3": + version "1.15.3" + resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.15.3.tgz#fb602cd4c2f0b7c0fb857e922075fdf677d25d84" + integrity sha512-5oiXqR7kwDGZ6+gmzIO2lTC+QsriNuQXZDWNYRV3l2XRN/zmPgnC21DLSx2D05zvD8vnXW6qUg7JnXZ4I6qLVQ== + "@types/webpack-hot-middleware@^2.25.3": version "2.25.3" resolved "https://registry.yarnpkg.com/@types/webpack-hot-middleware/-/webpack-hot-middleware-2.25.3.tgz#ba6265ada359cae4f437d8ac08ac5b8c616f7521" @@ -2209,16 +2214,24 @@ eslint-scope "^5.0.0" eslint-utils "^2.0.0" -"@typescript-eslint/parser@^4.8.1": - version "4.8.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.8.1.tgz#4fe2fbdbb67485bafc4320b3ae91e34efe1219d1" - integrity sha512-QND8XSVetATHK9y2Ltc/XBl5Ro7Y62YuZKnPEwnNPB8E379fDsvzJ1dMJ46fg/VOmk0hXhatc+GXs5MaXuL5Uw== +"@typescript-eslint/parser@4.0.1": + version "4.0.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.0.1.tgz#73772080db7a7a4534a35d719e006f503e664dc3" + integrity sha512-1+qLmXHNAWSQ7RB6fdSQszAiA7JTwzakj5cNYjBTUmpH2cqilxMZEIV+DRKjVZs8NzP3ALmKexB0w/ExjcK9Iw== dependencies: - "@typescript-eslint/scope-manager" "4.8.1" - "@typescript-eslint/types" "4.8.1" - "@typescript-eslint/typescript-estree" "4.8.1" + "@typescript-eslint/scope-manager" "4.0.1" + "@typescript-eslint/types" "4.0.1" + "@typescript-eslint/typescript-estree" "4.0.1" debug "^4.1.1" +"@typescript-eslint/scope-manager@4.0.1": + version "4.0.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.0.1.tgz#24d93c3000bdfcc5a157dc4d32b742405a8631b5" + integrity sha512-u3YEXVJ8jsj7QCJk3om0Y457fy2euEOkkzxIB/LKU3MdyI+FJ2gI0M4aKEaXzwCSfNDiZ13a3lDo5DVozc+XLQ== + dependencies: + "@typescript-eslint/types" "4.0.1" + "@typescript-eslint/visitor-keys" "4.0.1" + "@typescript-eslint/scope-manager@4.8.1": version "4.8.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.8.1.tgz#e343c475f8f1d15801b546cb17d7f309b768fdce" @@ -2227,6 +2240,11 @@ "@typescript-eslint/types" "4.8.1" "@typescript-eslint/visitor-keys" "4.8.1" +"@typescript-eslint/types@4.0.1": + version "4.0.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.0.1.tgz#1cf72582f764931f085cb8230ff215980fe467b2" + integrity sha512-S+gD3fgbkZYW2rnbjugNMqibm9HpEjqZBZkTiI3PwbbNGWmAcxolWIUwZ0SKeG4Dy2ktpKKaI/6+HGYVH8Qrlg== + "@typescript-eslint/types@4.8.1": version "4.8.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.8.1.tgz#23829c73c5fc6f4fcd5346a7780b274f72fee222" @@ -2245,6 +2263,20 @@ semver "^7.3.2" tsutils "^3.17.1" +"@typescript-eslint/typescript-estree@4.0.1": + version "4.0.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.0.1.tgz#29a43c7060641ec51c902d9f50ac7c5866ec479f" + integrity sha512-zGzleORFXrRWRJAMLTB2iJD1IZbCPkg4hsI8mGdpYlKaqzvKYSEWVAYh14eauaR+qIoZVWrXgYSXqLtTlxotiw== + dependencies: + "@typescript-eslint/types" "4.0.1" + "@typescript-eslint/visitor-keys" "4.0.1" + debug "^4.1.1" + globby "^11.0.1" + is-glob "^4.0.1" + lodash "^4.17.15" + semver "^7.3.2" + tsutils "^3.17.1" + "@typescript-eslint/typescript-estree@4.8.1": version "4.8.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.8.1.tgz#7307e3f2c9e95df7daa8dc0a34b8c43b7ec0dd32" @@ -2259,6 +2291,14 @@ semver "^7.3.2" tsutils "^3.17.1" +"@typescript-eslint/visitor-keys@4.0.1": + version "4.0.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.0.1.tgz#d4e8de62775f2a6db71c7e8539633680039fdd6c" + integrity sha512-yBSqd6FjnTzbg5RUy9J+9kJEyQjTI34JdGMJz+9ttlJzLCnGkBikxw+N5n2VDcc3CesbIEJ0MnZc5uRYnrEnCw== + dependencies: + "@typescript-eslint/types" "4.0.1" + eslint-visitor-keys "^2.0.0" + "@typescript-eslint/visitor-keys@4.8.1": version "4.8.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.8.1.tgz#794f68ee292d1b2e3aa9690ebedfcb3a8c90e3c3"