diff --git a/config/dependencies.yaml b/config/dependencies.yaml index 463e35b3489..656e05c3b13 100644 --- a/config/dependencies.yaml +++ b/config/dependencies.yaml @@ -324,6 +324,7 @@ org: 'lodash.orderby': *_orderby 'lodash.set': *_set 'next': *next + 'react-dropzone': '14.2.3' 'react-hotkeys-hook': *reactHotkeysHook 'react-instantsearch-dom': *reactInstantsearchDom 'react-markdown': *reactMarkdown diff --git a/sites/backend/src/index.mjs b/sites/backend/src/index.mjs index e04f596ef23..59e182ce6d5 100644 --- a/sites/backend/src/index.mjs +++ b/sites/backend/src/index.mjs @@ -25,7 +25,7 @@ import { openapi } from '../openapi/index.mjs' const config = verifyConfig() const prisma = new PrismaClient() const app = express() -app.use(express.json()) +app.use(express.json({ limit: '12mb' })) // Required for img upload app.use(express.static('public')) app.use('/docs', swaggerUi.serve, swaggerUi.setup(openapi)) diff --git a/sites/backend/src/middleware.mjs b/sites/backend/src/middleware.mjs index d6e1274abe3..7ba919b177e 100644 --- a/sites/backend/src/middleware.mjs +++ b/sites/backend/src/middleware.mjs @@ -1,4 +1,3 @@ -//import bodyParser from 'body-parser' import cors from 'cors' import http from 'passport-http' import jwt from 'passport-jwt' @@ -14,8 +13,6 @@ const levelFromRole = (role) => { } function loadExpressMiddleware(app) { - // FIXME: Is this still needed in FreeSewing v3? - //app.use(bodyParser.urlencoded({ extended: true })) app.use(cors()) } diff --git a/sites/org/components/account/img/img.en.yaml b/sites/org/components/account/img/img.en.yaml index 24b223a8e58..03412572965 100644 --- a/sites/org/components/account/img/img.en.yaml +++ b/sites/org/components/account/img/img.en.yaml @@ -1,4 +1,6 @@ title: How about a picture too? -bioPreview: Bio Preview +dragAndDropImageHere: Drag and drop an image here +selectImage: Select an image +or: or save: Save continue: Continue diff --git a/sites/org/components/account/img/index.js b/sites/org/components/account/img/index.js index eaeb2afd830..fcf73ffa51e 100644 --- a/sites/org/components/account/img/index.js +++ b/sites/org/components/account/img/index.js @@ -1,8 +1,9 @@ -import { useState } from 'react' +import { useState, useCallback } from 'react' import { useTranslation } from 'next-i18next' import useBackend from 'site/hooks/useBackend.js' import Link from 'next/link' import { Choice, Icons, welcomeSteps } from '../shared.js' +import { useDropzone } from 'react-dropzone' export const namespaces = ['img'] @@ -19,10 +20,21 @@ const Tab = ({ id, activeTab, setActiveTab, t }) => ( const UsernameSettings = ({ app, title = false, welcome = false }) => { const backend = useBackend(app) const { t } = useTranslation(namespaces) - const [bio, setBio] = useState(app.account.bio) + + const [img, setImg] = useState(false) + + const onDrop = useCallback((acceptedFiles) => { + const reader = new FileReader() + reader.onload = () => { + setImg(reader.result) + } + acceptedFiles.forEach((file) => reader.readAsDataURL(file)) + }, []) + + const { getRootProps, getInputProps } = useDropzone({ onDrop }) const save = async () => { - const result = await backend.updateAccount({ bio }) + const result = await backend.updateAccount({ img }) } const nextHref = '/docs/guide' @@ -30,9 +42,25 @@ const UsernameSettings = ({ app, title = false, welcome = false }) => { return ( <> {title ?

{t('title')}

: null} -
fixme
- + + + {welcome ? ( diff --git a/sites/org/components/wrappers/auth/index.js b/sites/org/components/wrappers/auth/index.js index 8c9a3fbb03c..76f8751c49e 100644 --- a/sites/org/components/wrappers/auth/index.js +++ b/sites/org/components/wrappers/auth/index.js @@ -1,5 +1,6 @@ import Link from 'next/link' import { useTranslation } from 'next-i18next' +import Loader from 'shared/components/loader.js' export const namespaces = ['auth'] @@ -84,6 +85,7 @@ const ConsentLacking = ({ t }) => ( const AuthWrapper = ({ children, app }) => { const { t } = useTranslation(namespaces) + if (!app.accountReady) return if (!app.token || !app.account?.username) return if (app.account.status !== 1) { if (app.account.status === 0) return diff --git a/sites/org/hooks/useApp.js b/sites/org/hooks/useApp.js index d351f13dda5..c6b559a1b29 100644 --- a/sites/org/hooks/useApp.js +++ b/sites/org/hooks/useApp.js @@ -86,7 +86,7 @@ function useApp({ bugsnag }) { const { t } = useTranslation() // Persistent state - const [account, setAccount] = useLocalStorage('account', { username: false }) + const [account, setAccount, accountReady] = useLocalStorage('account', { username: false }) const [token, setToken] = useLocalStorage('token', null) const [theme, setTheme] = useTheme() @@ -145,6 +145,7 @@ function useApp({ bugsnag }) { // State account, + accountReady, token, loading, navigation, diff --git a/sites/org/package.json b/sites/org/package.json index 86299c94aad..68c24c95978 100644 --- a/sites/org/package.json +++ b/sites/org/package.json @@ -39,6 +39,7 @@ "lodash.orderby": "4.6.0", "lodash.set": "4.3.2", "next": "13.1.1", + "react-dropzone": "14.2.3", "react-hotkeys-hook": "4.3.2", "react-instantsearch-dom": "6.38.2", "react-markdown": "8.0.4", diff --git a/sites/shared/components/loader.js b/sites/shared/components/loader.js index 24e31027570..4bb8e16a786 100644 --- a/sites/shared/components/loader.js +++ b/sites/shared/components/loader.js @@ -1,4 +1,4 @@ -import Spinner from 'shared/components/spinner' +import Spinner from 'shared/components/icons/spinner.js' const Loader = ({}) => (
( `} >
- +
) diff --git a/yarn.lock b/yarn.lock index a2f91ee3f5b..2a861bc1ca8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6003,6 +6003,11 @@ atomic-sleep@^1.0.0: resolved "https://registry.yarnpkg.com/atomic-sleep/-/atomic-sleep-1.0.0.tgz#eb85b77a601fc932cfe432c5acd364a9e2c9075b" integrity sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ== +attr-accept@^2.2.2: + version "2.2.2" + resolved "https://registry.yarnpkg.com/attr-accept/-/attr-accept-2.2.2.tgz#646613809660110749e92f2c10833b70968d929b" + integrity sha512-7prDjvt9HmqiZ0cl5CRjtS84sEyhsHP2coDkaZKRKVfCDo9s7iw7ChVmar78Gu9pC4SoR/28wFu/G5JJhTnqEg== + autoprefixer@10.4.13, autoprefixer@^10.4.0, autoprefixer@^10.4.13: version "10.4.13" resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-10.4.13.tgz#b5136b59930209a321e9fa3dca2e7c4d223e83a8" @@ -9712,6 +9717,13 @@ file-saver@2.0.5: resolved "https://registry.yarnpkg.com/file-saver/-/file-saver-2.0.5.tgz#d61cfe2ce059f414d899e9dd6d4107ee25670c38" integrity sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA== +file-selector@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/file-selector/-/file-selector-0.6.0.tgz#fa0a8d9007b829504db4d07dd4de0310b65287dc" + integrity sha512-QlZ5yJC0VxHxQQsQhXvBaC7VRJ2uaxTf+Tfpu4Z/OcVQJVpZO+DGU0rkoVW5ce2SccxugvpBJoMvUs59iILYdw== + dependencies: + tslib "^2.4.0" + file-uri-to-path@1: version "1.0.0" resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd" @@ -16666,6 +16678,15 @@ react-dom@18.2.0: loose-envify "^1.1.0" scheduler "^0.23.0" +react-dropzone@14.2.3: + version "14.2.3" + resolved "https://registry.yarnpkg.com/react-dropzone/-/react-dropzone-14.2.3.tgz#0acab68308fda2d54d1273a1e626264e13d4e84b" + integrity sha512-O3om8I+PkFKbxCukfIR3QAGftYXDZfOE2N1mr/7qebQJHs7U+/RSL/9xomJNpRg9kM5h9soQSdf0Gc7OHF5Fug== + dependencies: + attr-accept "^2.2.2" + file-selector "^0.6.0" + prop-types "^15.8.1" + react-fast-compare@^3.0.0, react-fast-compare@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-3.2.0.tgz#641a9da81b6a6320f270e89724fb45a0b39e43bb"