Compare commits
36 Commits
Author | SHA1 | Date | |
---|---|---|---|
d51de554d6 | |||
a068d31d14 | |||
3d185bf044 | |||
6cfee0f6a3 | |||
66f3e0475f | |||
dee8cc2c41 | |||
91a87199c4 | |||
38e227a9d4 | |||
c4bb7c9b17 | |||
88f1cedcdc | |||
c75dc80f82 | |||
351834633f | |||
7c01246028 | |||
ad64f1c571 | |||
19fc29ad47 | |||
7ad3d226dc | |||
d8cedd7b77 | |||
177676e180 | |||
db4ab7cf6f | |||
8f9ff8de07 | |||
21ee6f1d66 | |||
10b1e568d2 | |||
1882073973 | |||
567829fa3a | |||
c0e2c547ef | |||
f555e406ef | |||
4cd817bb01 | |||
41e9162454 | |||
ff2decc894 | |||
d44a401348 | |||
cb2ddbf661 | |||
25261b54ef | |||
0028974c3b | |||
4141f1eeab | |||
5ef8f18060 | |||
8bb4ef8b54 |
@ -1,5 +1,3 @@
|
|||||||
version: '3.0'
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
workspace:
|
workspace:
|
||||||
build:
|
build:
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
.next
|
|
||||||
.lighthouseci
|
|
||||||
coverage
|
|
||||||
node_modules
|
|
||||||
next-env.d.ts
|
|
||||||
**/workbox-*.js
|
|
||||||
**/sw.js
|
|
@ -6,8 +6,7 @@
|
|||||||
},
|
},
|
||||||
"env": {
|
"env": {
|
||||||
"node": true,
|
"node": true,
|
||||||
"browser": true,
|
"browser": true
|
||||||
"jest": true
|
|
||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
"prettier/prettier": "error",
|
"prettier/prettier": "error",
|
||||||
|
2
.github/workflows/analyze.yml
vendored
2
.github/workflows/analyze.yml
vendored
@ -16,7 +16,7 @@ jobs:
|
|||||||
language: ['javascript']
|
language: ['javascript']
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: 'actions/checkout@v2.3.4'
|
- uses: 'actions/checkout@v3.0.0'
|
||||||
|
|
||||||
- name: 'Initialize CodeQL'
|
- name: 'Initialize CodeQL'
|
||||||
uses: 'github/codeql-action/init@v1'
|
uses: 'github/codeql-action/init@v1'
|
||||||
|
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@ -10,10 +10,10 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: 'ubuntu-latest'
|
runs-on: 'ubuntu-latest'
|
||||||
steps:
|
steps:
|
||||||
- uses: 'actions/checkout@v2'
|
- uses: 'actions/checkout@v3.0.0'
|
||||||
|
|
||||||
- name: 'Use Node.js'
|
- name: 'Use Node.js'
|
||||||
uses: 'actions/setup-node@v2.4.1'
|
uses: 'actions/setup-node@v3.0.0'
|
||||||
with:
|
with:
|
||||||
node-version: '16.x'
|
node-version: '16.x'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
|
4
.github/workflows/lint.yml
vendored
4
.github/workflows/lint.yml
vendored
@ -10,10 +10,10 @@ jobs:
|
|||||||
lint:
|
lint:
|
||||||
runs-on: 'ubuntu-latest'
|
runs-on: 'ubuntu-latest'
|
||||||
steps:
|
steps:
|
||||||
- uses: 'actions/checkout@v2'
|
- uses: 'actions/checkout@v3.0.0'
|
||||||
|
|
||||||
- name: 'Use Node.js'
|
- name: 'Use Node.js'
|
||||||
uses: 'actions/setup-node@v2.4.1'
|
uses: 'actions/setup-node@v3.0.0'
|
||||||
with:
|
with:
|
||||||
node-version: '16.x'
|
node-version: '16.x'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
|
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -8,7 +8,7 @@ jobs:
|
|||||||
release:
|
release:
|
||||||
runs-on: 'ubuntu-latest'
|
runs-on: 'ubuntu-latest'
|
||||||
steps:
|
steps:
|
||||||
- uses: 'actions/checkout@v2.3.4'
|
- uses: 'actions/checkout@v3.0.0'
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
12
.github/workflows/test.yml
vendored
12
.github/workflows/test.yml
vendored
@ -10,10 +10,10 @@ jobs:
|
|||||||
test-unit:
|
test-unit:
|
||||||
runs-on: 'ubuntu-latest'
|
runs-on: 'ubuntu-latest'
|
||||||
steps:
|
steps:
|
||||||
- uses: 'actions/checkout@v2.3.4'
|
- uses: 'actions/checkout@v3.0.0'
|
||||||
|
|
||||||
- name: 'Use Node.js'
|
- name: 'Use Node.js'
|
||||||
uses: 'actions/setup-node@v2.4.1'
|
uses: 'actions/setup-node@v3.0.0'
|
||||||
with:
|
with:
|
||||||
node-version: '16.x'
|
node-version: '16.x'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@ -27,10 +27,10 @@ jobs:
|
|||||||
test-lighthouse:
|
test-lighthouse:
|
||||||
runs-on: 'ubuntu-latest'
|
runs-on: 'ubuntu-latest'
|
||||||
steps:
|
steps:
|
||||||
- uses: 'actions/checkout@v2.3.4'
|
- uses: 'actions/checkout@v3.0.0'
|
||||||
|
|
||||||
- name: 'Use Node.js'
|
- name: 'Use Node.js'
|
||||||
uses: 'actions/setup-node@v2.4.0'
|
uses: 'actions/setup-node@v3.0.0'
|
||||||
with:
|
with:
|
||||||
node-version: '16.x'
|
node-version: '16.x'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@ -52,10 +52,10 @@ jobs:
|
|||||||
test-e2e:
|
test-e2e:
|
||||||
runs-on: 'ubuntu-latest'
|
runs-on: 'ubuntu-latest'
|
||||||
steps:
|
steps:
|
||||||
- uses: 'actions/checkout@v2.3.4'
|
- uses: 'actions/checkout@v3.0.0'
|
||||||
|
|
||||||
- name: 'Use Node.js'
|
- name: 'Use Node.js'
|
||||||
uses: 'actions/setup-node@v2.4.0'
|
uses: 'actions/setup-node@v3.0.0'
|
||||||
with:
|
with:
|
||||||
node-version: '16.x'
|
node-version: '16.x'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -49,3 +49,4 @@ npm-debug.log*
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
.lighthouseci
|
.lighthouseci
|
||||||
.vercel
|
.vercel
|
||||||
|
*.hbs
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
{
|
{
|
||||||
"*": ["editorconfig-checker"],
|
"*": ["editorconfig-checker"],
|
||||||
"*.{js,jsx,ts,tsx}": [
|
"*.{js,jsx,ts,tsx}": ["prettier --write", "eslint --fix"],
|
||||||
"prettier --write",
|
|
||||||
"eslint --fix",
|
|
||||||
"jest --findRelatedTests"
|
|
||||||
],
|
|
||||||
"*.{css,scss,sass,json,jsonc,yml,yaml}": ["prettier --write"],
|
"*.{css,scss,sass,json,jsonc,yml,yaml}": ["prettier --write"],
|
||||||
"*.md": ["prettier --write", "markdownlint --dot --fix"]
|
"*.{md,mdx}": ["prettier --write", "markdownlint-cli2 --fix"]
|
||||||
}
|
}
|
||||||
|
11
.markdownlint-cli2.jsonc
Normal file
11
.markdownlint-cli2.jsonc
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"config": {
|
||||||
|
"default": true,
|
||||||
|
"MD013": false,
|
||||||
|
"MD024": false,
|
||||||
|
"MD033": false,
|
||||||
|
"MD041": false
|
||||||
|
},
|
||||||
|
"globs": ["**/*.{md,mdx}"],
|
||||||
|
"ignores": ["**/node_modules"]
|
||||||
|
}
|
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"default": true,
|
|
||||||
"MD013": false,
|
|
||||||
"MD033": false,
|
|
||||||
"MD041": false
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
.next
|
|
||||||
.lighthouseci
|
|
||||||
coverage
|
|
||||||
node_modules
|
|
||||||
**/workbox-*.js
|
|
||||||
**/sw.js
|
|
||||||
*.hbs
|
|
@ -1,15 +1,15 @@
|
|||||||
FROM node:16.14.2 AS dependencies
|
FROM node:16.17.0 AS dependencies
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
COPY ./package*.json ./
|
COPY ./package*.json ./
|
||||||
RUN npm install
|
RUN npm install
|
||||||
|
|
||||||
FROM node:16.14.2 AS builder
|
FROM node:16.17.0 AS builder
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
COPY ./ ./
|
COPY ./ ./
|
||||||
COPY --from=dependencies /usr/src/app/node_modules ./node_modules
|
COPY --from=dependencies /usr/src/app/node_modules ./node_modules
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
FROM node:16.14.2 AS runner
|
FROM node:16.17.0 AS runner
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
COPY --from=builder /usr/src/app/next.config.js ./next.config.js
|
COPY --from=builder /usr/src/app/next.config.js ./next.config.js
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
Thream's website to stay close with your friends and communities.
|
Thream's website to stay close with your friends and communities.
|
||||||
|
|
||||||
It uses [Thream/api](https://github.com/Thream/api) [v1.0.1](https://github.com/Thream/api/releases/tag/v1.0.1).
|
It uses [Thream/api](https://github.com/Thream/api) [v1.2.0](https://github.com/Thream/api/releases/tag/v1.2.0).
|
||||||
|
|
||||||
## ⚙️ Getting Started
|
## ⚙️ Getting Started
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ npm run dev
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
# Setup and run all the services for you
|
# Setup and run all the services for you
|
||||||
docker-compose up --build
|
docker compose up --build
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Services started
|
#### Services started
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
import Image from 'next/image'
|
import Image from 'next/image'
|
||||||
import { PlusIcon, MenuIcon, UsersIcon, XIcon } from '@heroicons/react/solid'
|
import { PlusIcon, MenuIcon, UsersIcon, XIcon } from '@heroicons/react/solid'
|
||||||
import classNames from 'classnames'
|
import classNames from 'clsx'
|
||||||
import { useMediaQuery } from 'react-responsive'
|
import { useMediaQuery } from 'react-responsive'
|
||||||
import { useSwipeable } from 'react-swipeable'
|
import { useSwipeable } from 'react-swipeable'
|
||||||
|
|
||||||
@ -40,7 +40,9 @@ export interface ApplicationProps {
|
|||||||
title: string
|
title: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Application: React.FC<ApplicationProps> = (props) => {
|
export const Application: React.FC<
|
||||||
|
React.PropsWithChildren<ApplicationProps>
|
||||||
|
> = (props) => {
|
||||||
const { children, path, guildLeftSidebar, title } = props
|
const { children, path, guildLeftSidebar, title } = props
|
||||||
|
|
||||||
const { user } = useAuthentication()
|
const { user } = useAuthentication()
|
||||||
@ -110,7 +112,7 @@ export const Application: React.FC<ApplicationProps> = (props) => {
|
|||||||
const swipeableHandlers = useSwipeable({
|
const swipeableHandlers = useSwipeable({
|
||||||
trackMouse: false,
|
trackMouse: false,
|
||||||
trackTouch: true,
|
trackTouch: true,
|
||||||
preventDefaultTouchmoveEvent: true,
|
preventScrollOnSwipe: true,
|
||||||
onSwipedRight: () => {
|
onSwipedRight: () => {
|
||||||
if (visibleSidebars.right) {
|
if (visibleSidebars.right) {
|
||||||
return setVisibleSidebars({ ...visibleSidebars, right: false })
|
return setVisibleSidebars({ ...visibleSidebars, right: false })
|
||||||
@ -121,6 +123,7 @@ export const Application: React.FC<ApplicationProps> = (props) => {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
onSwipedLeft: () => {
|
onSwipedLeft: () => {
|
||||||
|
if (isGuildsChannelsPath(path)) {
|
||||||
if (visibleSidebars.left) {
|
if (visibleSidebars.left) {
|
||||||
return setVisibleSidebars({ ...visibleSidebars, left: false })
|
return setVisibleSidebars({ ...visibleSidebars, left: false })
|
||||||
}
|
}
|
||||||
@ -129,6 +132,7 @@ export const Application: React.FC<ApplicationProps> = (props) => {
|
|||||||
right: true
|
right: true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -213,7 +217,7 @@ export const Application: React.FC<ApplicationProps> = (props) => {
|
|||||||
id='application-page-content'
|
id='application-page-content'
|
||||||
onClick={handleCloseSidebars}
|
onClick={handleCloseSidebars}
|
||||||
className={classNames(
|
className={classNames(
|
||||||
'h-full-without-header top-0 z-0 flex w-full flex-1 flex-col overflow-y-auto transition',
|
'h-full-without-header relative top-0 z-0 flex w-full flex-1 flex-col overflow-y-auto transition',
|
||||||
{
|
{
|
||||||
'absolute opacity-20':
|
'absolute opacity-20':
|
||||||
isMobile && (visibleSidebars.left || visibleSidebars.right)
|
isMobile && (visibleSidebars.left || visibleSidebars.right)
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { Form } from 'react-component-form'
|
import { Form, useForm } from 'react-component-form'
|
||||||
import useTranslation from 'next-translate/useTranslation'
|
import useTranslation from 'next-translate/useTranslation'
|
||||||
|
import classNames from 'clsx'
|
||||||
|
import axios from 'axios'
|
||||||
|
import type { HandleUseFormCallback } from 'react-component-form'
|
||||||
|
|
||||||
import { HandleSubmitCallback, useForm } from '../../../hooks/useForm'
|
|
||||||
import { FormState } from '../../design/FormState'
|
import { FormState } from '../../design/FormState'
|
||||||
import { useGuildMember } from '../../../contexts/GuildMember'
|
import { useGuildMember } from '../../../contexts/GuildMember'
|
||||||
import { Input } from '../../design/Input'
|
import { Input } from '../../design/Input'
|
||||||
@ -14,6 +16,12 @@ import {
|
|||||||
channelSchema,
|
channelSchema,
|
||||||
ChannelWithDefaultChannelId
|
ChannelWithDefaultChannelId
|
||||||
} from '../../../models/Channel'
|
} from '../../../models/Channel'
|
||||||
|
import { ConfirmPopup } from '../ConfirmPopup'
|
||||||
|
import { useFormTranslation } from '../../../hooks/useFormTranslation'
|
||||||
|
|
||||||
|
const schema = {
|
||||||
|
name: channelSchema.name
|
||||||
|
}
|
||||||
|
|
||||||
export interface ChannelSettingsProps {
|
export interface ChannelSettingsProps {
|
||||||
channel: Channel
|
channel: Channel
|
||||||
@ -31,26 +39,26 @@ export const ChannelSettings: React.FC<ChannelSettingsProps> = (props) => {
|
|||||||
name: channel.name
|
name: channel.name
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const [confirmation, setConfirmation] = useState(false)
|
||||||
|
|
||||||
|
const handleConfirmation = (): void => {
|
||||||
|
return setConfirmation(!confirmation)
|
||||||
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
handleUseForm,
|
||||||
fetchState,
|
fetchState,
|
||||||
message,
|
message,
|
||||||
errors,
|
errors,
|
||||||
getErrorTranslation,
|
|
||||||
handleSubmit,
|
|
||||||
setFetchState,
|
setFetchState,
|
||||||
setMessageTranslationKey
|
setMessage
|
||||||
} = useForm({
|
} = useForm(schema)
|
||||||
validateSchema: {
|
const { getFirstErrorTranslation } = useFormTranslation()
|
||||||
name: channelSchema.name
|
|
||||||
},
|
|
||||||
replaceEmptyStringToNull: true,
|
|
||||||
resetOnSuccess: false
|
|
||||||
})
|
|
||||||
|
|
||||||
const onSubmit: HandleSubmitCallback = async (formData) => {
|
const onSubmit: HandleUseFormCallback<typeof schema> = async (formData) => {
|
||||||
try {
|
try {
|
||||||
await authentication.api.put(`/channels/${channel.id}`, formData)
|
await authentication.api.put(`/channels/${channel.id}`, formData)
|
||||||
setInputValues(formData as any)
|
setInputValues(formData)
|
||||||
await router.push(`/application/${guild.id}/${channel.id}`)
|
await router.push(`/application/${guild.id}/${channel.id}`)
|
||||||
return null
|
return null
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -81,13 +89,18 @@ export const ChannelSettings: React.FC<ChannelSettingsProps> = (props) => {
|
|||||||
await router.push(`/application/${guild.id}/${data.defaultChannelId}`)
|
await router.push(`/application/${guild.id}/${data.defaultChannelId}`)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setFetchState('error')
|
setFetchState('error')
|
||||||
setMessageTranslationKey('errors:server-error')
|
if (axios.isAxiosError(error) && error.response?.status === 400) {
|
||||||
|
setMessage('application:delete-channel-only-one')
|
||||||
|
} else {
|
||||||
|
setMessage('errors:server-error')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<Form
|
<Form
|
||||||
onSubmit={handleSubmit(onSubmit)}
|
onSubmit={handleUseForm(onSubmit)}
|
||||||
className='my-auto flex flex-col items-center justify-center py-12'
|
className='my-auto flex flex-col items-center justify-center py-12'
|
||||||
>
|
>
|
||||||
<div className='flex w-full flex-col items-center justify-center sm:w-fit lg:flex-row'>
|
<div className='flex w-full flex-col items-center justify-center sm:w-fit lg:flex-row'>
|
||||||
@ -100,7 +113,7 @@ export const ChannelSettings: React.FC<ChannelSettingsProps> = (props) => {
|
|||||||
className='!mt-0'
|
className='!mt-0'
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
value={inputValues.name}
|
value={inputValues.name}
|
||||||
error={getErrorTranslation(errors.name)}
|
error={getFirstErrorTranslation(errors.name)}
|
||||||
data-cy='channel-name-input'
|
data-cy='channel-name-input'
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -115,7 +128,7 @@ export const ChannelSettings: React.FC<ChannelSettingsProps> = (props) => {
|
|||||||
<Button
|
<Button
|
||||||
type='button'
|
type='button'
|
||||||
color='red'
|
color='red'
|
||||||
onClick={handleDelete}
|
onClick={handleConfirmation}
|
||||||
data-cy='button-delete-channel-settings'
|
data-cy='button-delete-channel-settings'
|
||||||
>
|
>
|
||||||
{t('application:delete')}
|
{t('application:delete')}
|
||||||
@ -124,5 +137,21 @@ export const ChannelSettings: React.FC<ChannelSettingsProps> = (props) => {
|
|||||||
<FormState state={fetchState} message={message} />
|
<FormState state={fetchState} message={message} />
|
||||||
</div>
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
|
<div
|
||||||
|
className={classNames(
|
||||||
|
'pointer-events-none invisible absolute z-50 flex h-full w-full items-center justify-center bg-black bg-opacity-90 opacity-0 backdrop-blur-md transition-all',
|
||||||
|
{ 'pointer-events-auto !visible !opacity-100': confirmation }
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<ConfirmPopup
|
||||||
|
className={classNames('relative top-8 transition-all', {
|
||||||
|
'!top-0': confirmation
|
||||||
|
})}
|
||||||
|
handleYes={handleDelete}
|
||||||
|
handleNo={handleConfirmation}
|
||||||
|
title={`${t('application:delete-the-channel')} ?`}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
import classNames from 'classnames'
|
import { memo } from 'react'
|
||||||
|
import classNames from 'clsx'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import { CogIcon } from '@heroicons/react/solid'
|
import { CogIcon } from '@heroicons/react/solid'
|
||||||
|
|
||||||
import { GuildsChannelsPath } from '../../Application'
|
import { GuildsChannelsPath } from '../Application'
|
||||||
import { Channel as ChannelType } from '../../../../models/Channel'
|
import { Channel as ChannelType } from '../../../models/Channel'
|
||||||
import { useGuildMember } from '../../../../contexts/GuildMember'
|
import { useGuildMember } from '../../../contexts/GuildMember'
|
||||||
import { IconButton } from '../../../design/IconButton'
|
import { IconButton } from '../../design/IconButton'
|
||||||
|
|
||||||
export interface ChannelProps {
|
export interface ChannelProps {
|
||||||
path: GuildsChannelsPath
|
path: GuildsChannelsPath
|
||||||
@ -14,7 +15,7 @@ export interface ChannelProps {
|
|||||||
selected?: boolean
|
selected?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Channel: React.FC<ChannelProps> = (props) => {
|
const ChannelMemo: React.FC<ChannelProps> = (props) => {
|
||||||
const { channel, path, selected = false } = props
|
const { channel, path, selected = false } = props
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
@ -53,3 +54,5 @@ export const Channel: React.FC<ChannelProps> = (props) => {
|
|||||||
</Link>
|
</Link>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const Channel = memo(ChannelMemo)
|
@ -1 +0,0 @@
|
|||||||
export * from './Channel'
|
|
@ -1 +0,0 @@
|
|||||||
export * from './ConfirmGuildJoin'
|
|
@ -1,19 +1,18 @@
|
|||||||
import Image from 'next/image'
|
import Image from 'next/image'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import useTranslation from 'next-translate/useTranslation'
|
import useTranslation from 'next-translate/useTranslation'
|
||||||
import classNames from 'classnames'
|
import classNames from 'clsx'
|
||||||
|
|
||||||
import { Loader } from '../../design/Loader'
|
import { Loader } from '../../design/Loader'
|
||||||
|
|
||||||
export interface ConfirmGuildJoinProps {
|
export interface ConfirmPopupProps {
|
||||||
className?: string
|
className?: string
|
||||||
|
title: string
|
||||||
handleYes: () => void | Promise<void>
|
handleYes: () => void | Promise<void>
|
||||||
handleNo: () => void | Promise<void>
|
handleNo: () => void | Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ConfirmGuildJoin: React.FC<ConfirmGuildJoinProps> = ({
|
export const ConfirmPopup: React.FC<ConfirmPopupProps> = ({ ...props }) => {
|
||||||
...props
|
|
||||||
}) => {
|
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
|
||||||
@ -25,9 +24,12 @@ export const ConfirmGuildJoin: React.FC<ConfirmGuildJoinProps> = ({
|
|||||||
return (
|
return (
|
||||||
<div className={props.className}>
|
<div className={props.className}>
|
||||||
<Loader
|
<Loader
|
||||||
className={classNames('absolute scale-0 transition', {
|
className={classNames(
|
||||||
|
'absolute top-1/2 left-1/2 scale-0 transition-all',
|
||||||
|
{
|
||||||
'scale-100': isLoading
|
'scale-100': isLoading
|
||||||
})}
|
}
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
className={classNames(
|
className={classNames(
|
||||||
@ -40,24 +42,24 @@ export const ConfirmGuildJoin: React.FC<ConfirmGuildJoinProps> = ({
|
|||||||
<Image
|
<Image
|
||||||
quality={100}
|
quality={100}
|
||||||
src='/images/svg/design/join-guild.svg'
|
src='/images/svg/design/join-guild.svg'
|
||||||
alt='Join Guild Illustration'
|
alt='Illustration'
|
||||||
height={150}
|
height={150}
|
||||||
width={150}
|
width={150}
|
||||||
/>
|
/>
|
||||||
<div className='mt-8 flex flex-col'>
|
<div className='mt-8 flex flex-col'>
|
||||||
<h1 className='mb-6 text-center text-xl'>
|
<h1 className='mb-6 text-center text-xl'>{props.title}</h1>
|
||||||
{t('application:join-the-guild')} ?
|
|
||||||
</h1>
|
|
||||||
<div className='flex gap-7'>
|
<div className='flex gap-7'>
|
||||||
<button
|
<button
|
||||||
className='rounded-3xl bg-success px-8 py-2 text-white transition hover:brightness-125 dark:text-black hover:dark:brightness-75'
|
className='rounded-3xl bg-success px-8 py-2 text-white transition hover:brightness-125 dark:text-black hover:dark:brightness-75'
|
||||||
onClick={handleYesLoading}
|
onClick={handleYesLoading}
|
||||||
|
data-cy='confirm-popup-yes-button'
|
||||||
>
|
>
|
||||||
{t('common:yes')}
|
{t('common:yes')}
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className='rounded-3xl bg-error px-8 py-2 text-white transition hover:brightness-125 dark:text-black hover:dark:brightness-75'
|
className='rounded-3xl bg-error px-8 py-2 text-white transition hover:brightness-125 dark:text-black hover:dark:brightness-75'
|
||||||
onClick={props.handleNo}
|
onClick={props.handleNo}
|
||||||
|
data-cy='confirm-popup-no-button'
|
||||||
>
|
>
|
||||||
{t('common:no')}
|
{t('common:no')}
|
||||||
</button>
|
</button>
|
1
components/Application/ConfirmPopup/index.ts
Normal file
1
components/Application/ConfirmPopup/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './ConfirmPopup'
|
@ -1,32 +1,32 @@
|
|||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import useTranslation from 'next-translate/useTranslation'
|
import useTranslation from 'next-translate/useTranslation'
|
||||||
import { Form } from 'react-component-form'
|
import { Form, useForm } from 'react-component-form'
|
||||||
|
import type { HandleUseFormCallback } from 'react-component-form'
|
||||||
|
|
||||||
import { useAuthentication } from '../../../tools/authentication'
|
import { useAuthentication } from '../../../tools/authentication'
|
||||||
import { HandleSubmitCallback, useForm } from '../../../hooks/useForm'
|
|
||||||
import { Input } from '../../design/Input'
|
import { Input } from '../../design/Input'
|
||||||
import { Main } from '../../design/Main'
|
import { Main } from '../../design/Main'
|
||||||
import { Button } from '../../design/Button'
|
import { Button } from '../../design/Button'
|
||||||
import { FormState } from '../../design/FormState'
|
import { FormState } from '../../design/FormState'
|
||||||
import { Channel, channelSchema } from '../../../models/Channel'
|
import { Channel, channelSchema } from '../../../models/Channel'
|
||||||
import { useGuildMember } from '../../../contexts/GuildMember'
|
import { useGuildMember } from '../../../contexts/GuildMember'
|
||||||
|
import { useFormTranslation } from '../../../hooks/useFormTranslation'
|
||||||
|
|
||||||
|
const schema = {
|
||||||
|
name: channelSchema.name
|
||||||
|
}
|
||||||
|
|
||||||
export const CreateChannel: React.FC = () => {
|
export const CreateChannel: React.FC = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { guild } = useGuildMember()
|
const { guild } = useGuildMember()
|
||||||
|
|
||||||
const { fetchState, message, errors, getErrorTranslation, handleSubmit } =
|
const { handleUseForm, fetchState, message, errors } = useForm(schema)
|
||||||
useForm({
|
const { getFirstErrorTranslation } = useFormTranslation()
|
||||||
validateSchema: {
|
|
||||||
name: channelSchema.name
|
|
||||||
},
|
|
||||||
resetOnSuccess: true
|
|
||||||
})
|
|
||||||
|
|
||||||
const { authentication } = useAuthentication()
|
const { authentication } = useAuthentication()
|
||||||
|
|
||||||
const onSubmit: HandleSubmitCallback = async (formData) => {
|
const onSubmit: HandleUseFormCallback<typeof schema> = async (formData) => {
|
||||||
try {
|
try {
|
||||||
const { data: channel } = await authentication.api.post<Channel>(
|
const { data: channel } = await authentication.api.post<Channel>(
|
||||||
`/guilds/${guild.id}/channels`,
|
`/guilds/${guild.id}/channels`,
|
||||||
@ -44,13 +44,13 @@ export const CreateChannel: React.FC = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Main>
|
<Main>
|
||||||
<Form className='w-4/6 max-w-xs' onSubmit={handleSubmit(onSubmit)}>
|
<Form className='w-4/6 max-w-xs' onSubmit={handleUseForm(onSubmit)}>
|
||||||
<Input
|
<Input
|
||||||
type='text'
|
type='text'
|
||||||
placeholder={t('common:name')}
|
placeholder={t('common:name')}
|
||||||
name='name'
|
name='name'
|
||||||
label={t('common:name')}
|
label={t('common:name')}
|
||||||
error={getErrorTranslation(errors.name)}
|
error={getFirstErrorTranslation(errors.name)}
|
||||||
data-cy='channel-name-input'
|
data-cy='channel-name-input'
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
|
@ -1,33 +1,33 @@
|
|||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import useTranslation from 'next-translate/useTranslation'
|
import useTranslation from 'next-translate/useTranslation'
|
||||||
import { Form } from 'react-component-form'
|
import { Form, useForm } from 'react-component-form'
|
||||||
import { AxiosResponse } from 'axios'
|
import { AxiosResponse } from 'axios'
|
||||||
|
import type { HandleUseFormCallback } from 'react-component-form'
|
||||||
|
|
||||||
import { useAuthentication } from '../../../tools/authentication'
|
import { useAuthentication } from '../../../tools/authentication'
|
||||||
import { HandleSubmitCallback, useForm } from '../../../hooks/useForm'
|
|
||||||
import { GuildComplete, guildSchema } from '../../../models/Guild'
|
import { GuildComplete, guildSchema } from '../../../models/Guild'
|
||||||
import { Input } from '../../design/Input'
|
import { Input } from '../../design/Input'
|
||||||
import { Main } from '../../design/Main'
|
import { Main } from '../../design/Main'
|
||||||
import { Button } from '../../design/Button'
|
import { Button } from '../../design/Button'
|
||||||
import { FormState } from '../../design/FormState'
|
import { FormState } from '../../design/FormState'
|
||||||
import { Textarea } from '../../design/Textarea'
|
import { Textarea } from '../../design/Textarea'
|
||||||
|
import { useFormTranslation } from '../../../hooks/useFormTranslation'
|
||||||
|
|
||||||
|
const schema = {
|
||||||
|
name: guildSchema.name,
|
||||||
|
description: guildSchema.description
|
||||||
|
}
|
||||||
|
|
||||||
export const CreateGuild: React.FC = () => {
|
export const CreateGuild: React.FC = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
const { fetchState, message, errors, getErrorTranslation, handleSubmit } =
|
const { handleUseForm, fetchState, message, errors } = useForm(schema as any)
|
||||||
useForm({
|
const { getFirstErrorTranslation } = useFormTranslation()
|
||||||
validateSchema: {
|
|
||||||
name: guildSchema.name,
|
|
||||||
description: guildSchema.description
|
|
||||||
},
|
|
||||||
resetOnSuccess: true
|
|
||||||
})
|
|
||||||
|
|
||||||
const { authentication } = useAuthentication()
|
const { authentication } = useAuthentication()
|
||||||
|
|
||||||
const onSubmit: HandleSubmitCallback = async (formData) => {
|
const onSubmit: HandleUseFormCallback<any> = async (formData) => {
|
||||||
try {
|
try {
|
||||||
const { data } = await authentication.api.post<
|
const { data } = await authentication.api.post<
|
||||||
any,
|
any,
|
||||||
@ -47,13 +47,13 @@ export const CreateGuild: React.FC = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Main>
|
<Main>
|
||||||
<Form className='w-4/6 max-w-xs' onSubmit={handleSubmit(onSubmit)}>
|
<Form className='w-4/6 max-w-xs' onSubmit={handleUseForm(onSubmit)}>
|
||||||
<Input
|
<Input
|
||||||
type='text'
|
type='text'
|
||||||
placeholder={t('common:name')}
|
placeholder={t('common:name')}
|
||||||
name='name'
|
name='name'
|
||||||
label={t('common:name')}
|
label={t('common:name')}
|
||||||
error={getErrorTranslation(errors.name)}
|
error={getFirstErrorTranslation(errors.name)}
|
||||||
/>
|
/>
|
||||||
<Textarea
|
<Textarea
|
||||||
label='Description'
|
label='Description'
|
||||||
@ -64,7 +64,11 @@ export const CreateGuild: React.FC = () => {
|
|||||||
{t('application:create')}
|
{t('application:create')}
|
||||||
</Button>
|
</Button>
|
||||||
</Form>
|
</Form>
|
||||||
<FormState id='message' state={fetchState} message={message} />
|
<FormState
|
||||||
|
id='message'
|
||||||
|
state={fetchState}
|
||||||
|
message={message != null ? t(message) : undefined}
|
||||||
|
/>
|
||||||
</Main>
|
</Main>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,11 @@ import { useRouter } from 'next/router'
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { Type } from '@sinclair/typebox'
|
import { Type } from '@sinclair/typebox'
|
||||||
import { PhotographIcon } from '@heroicons/react/solid'
|
import { PhotographIcon } from '@heroicons/react/solid'
|
||||||
import { Form } from 'react-component-form'
|
import { Form, useForm } from 'react-component-form'
|
||||||
import useTranslation from 'next-translate/useTranslation'
|
import useTranslation from 'next-translate/useTranslation'
|
||||||
|
import classNames from 'clsx'
|
||||||
|
import type { HandleUseFormCallback } from 'react-component-form'
|
||||||
|
|
||||||
import { HandleSubmitCallback, useForm } from '../../../hooks/useForm'
|
|
||||||
import { guildSchema } from '../../../models/Guild'
|
import { guildSchema } from '../../../models/Guild'
|
||||||
import { FormState } from '../../design/FormState'
|
import { FormState } from '../../design/FormState'
|
||||||
import { useGuildMember } from '../../../contexts/GuildMember'
|
import { useGuildMember } from '../../../contexts/GuildMember'
|
||||||
@ -14,6 +15,13 @@ import { Textarea } from '../../design/Textarea'
|
|||||||
import { Input } from '../../design/Input'
|
import { Input } from '../../design/Input'
|
||||||
import { Button } from '../../design/Button'
|
import { Button } from '../../design/Button'
|
||||||
import { useAuthentication } from '../../../tools/authentication'
|
import { useAuthentication } from '../../../tools/authentication'
|
||||||
|
import { ConfirmPopup } from '../ConfirmPopup'
|
||||||
|
import { useFormTranslation } from '../../../hooks/useFormTranslation'
|
||||||
|
|
||||||
|
const schema = {
|
||||||
|
name: guildSchema.name,
|
||||||
|
description: Type.Optional(guildSchema.description)
|
||||||
|
}
|
||||||
|
|
||||||
export const GuildSettings: React.FC = () => {
|
export const GuildSettings: React.FC = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
@ -26,27 +34,26 @@ export const GuildSettings: React.FC = () => {
|
|||||||
description: guild.description
|
description: guild.description
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const [confirmation, setConfirmation] = useState(false)
|
||||||
|
|
||||||
|
const handleConfirmation = (): void => {
|
||||||
|
return setConfirmation(!confirmation)
|
||||||
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
handleUseForm,
|
||||||
fetchState,
|
fetchState,
|
||||||
message,
|
message,
|
||||||
errors,
|
errors,
|
||||||
getErrorTranslation,
|
|
||||||
handleSubmit,
|
|
||||||
setFetchState,
|
setFetchState,
|
||||||
setMessageTranslationKey
|
setMessage
|
||||||
} = useForm({
|
} = useForm(schema as any)
|
||||||
validateSchema: {
|
const { getFirstErrorTranslation } = useFormTranslation()
|
||||||
name: guildSchema.name,
|
|
||||||
description: Type.Optional(guildSchema.description)
|
|
||||||
},
|
|
||||||
replaceEmptyStringToNull: true,
|
|
||||||
resetOnSuccess: false
|
|
||||||
})
|
|
||||||
|
|
||||||
const onSubmit: HandleSubmitCallback = async (formData) => {
|
const onSubmit: HandleUseFormCallback<any> = async (formData) => {
|
||||||
try {
|
try {
|
||||||
await authentication.api.put(`/guilds/${guild.id}`, formData)
|
await authentication.api.put(`/guilds/${guild.id}`, formData)
|
||||||
setInputValues(formData as any)
|
setInputValues(formData as unknown as any)
|
||||||
return {
|
return {
|
||||||
type: 'success',
|
type: 'success',
|
||||||
value: 'application:saved-information'
|
value: 'application:saved-information'
|
||||||
@ -84,7 +91,7 @@ export const GuildSettings: React.FC = () => {
|
|||||||
setFetchState('idle')
|
setFetchState('idle')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setFetchState('error')
|
setFetchState('error')
|
||||||
setMessageTranslationKey('errors:server-error')
|
setMessage('errors:server-error')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,7 +101,7 @@ export const GuildSettings: React.FC = () => {
|
|||||||
await authentication.api.delete(`/guilds/${guild.id}`)
|
await authentication.api.delete(`/guilds/${guild.id}`)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setFetchState('error')
|
setFetchState('error')
|
||||||
setMessageTranslationKey('errors:server-error')
|
setMessage('errors:server-error')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,13 +111,14 @@ export const GuildSettings: React.FC = () => {
|
|||||||
await router.push('/application')
|
await router.push('/application')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setFetchState('error')
|
setFetchState('error')
|
||||||
setMessageTranslationKey('errors:server-error')
|
setMessage('errors:server-error')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<Form
|
<Form
|
||||||
onSubmit={handleSubmit(onSubmit)}
|
onSubmit={handleUseForm(onSubmit)}
|
||||||
className='my-auto flex flex-col items-center justify-center py-12'
|
className='my-auto flex flex-col items-center justify-center py-12'
|
||||||
>
|
>
|
||||||
{member.isOwner && (
|
{member.isOwner && (
|
||||||
@ -151,7 +159,7 @@ export const GuildSettings: React.FC = () => {
|
|||||||
className='!mt-0'
|
className='!mt-0'
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
value={inputValues.name}
|
value={inputValues.name}
|
||||||
error={getErrorTranslation(errors.name)}
|
error={getFirstErrorTranslation(errors.name)}
|
||||||
data-cy='guild-name-input'
|
data-cy='guild-name-input'
|
||||||
/>
|
/>
|
||||||
<Textarea
|
<Textarea
|
||||||
@ -177,7 +185,7 @@ export const GuildSettings: React.FC = () => {
|
|||||||
<Button
|
<Button
|
||||||
type='button'
|
type='button'
|
||||||
color='red'
|
color='red'
|
||||||
onClick={handleDelete}
|
onClick={handleConfirmation}
|
||||||
data-cy='button-delete-guild-settings'
|
data-cy='button-delete-guild-settings'
|
||||||
>
|
>
|
||||||
{t('application:delete')}
|
{t('application:delete')}
|
||||||
@ -195,9 +203,29 @@ export const GuildSettings: React.FC = () => {
|
|||||||
</div>
|
</div>
|
||||||
<FormState
|
<FormState
|
||||||
state={fetchState}
|
state={fetchState}
|
||||||
message={getErrorTranslation(errors.description) ?? message}
|
message={
|
||||||
|
message != null
|
||||||
|
? t(message)
|
||||||
|
: getFirstErrorTranslation(errors.email)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
|
<div
|
||||||
|
className={classNames(
|
||||||
|
'pointer-events-none invisible absolute z-50 flex h-full w-full items-center justify-center bg-black bg-opacity-90 opacity-0 backdrop-blur-md transition-all',
|
||||||
|
{ 'pointer-events-auto !visible !opacity-100': confirmation }
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<ConfirmPopup
|
||||||
|
className={classNames('relative top-8 transition-all', {
|
||||||
|
'!top-0': confirmation
|
||||||
|
})}
|
||||||
|
handleYes={handleDelete}
|
||||||
|
handleNo={handleConfirmation}
|
||||||
|
title={`${t('application:delete-the-guild')} ?`}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
|
import { memo } from 'react'
|
||||||
import Image from 'next/image'
|
import Image from 'next/image'
|
||||||
|
|
||||||
import { GuildWithDefaultChannelId } from '../../../../models/Guild'
|
import { GuildWithDefaultChannelId } from '../../../models/Guild'
|
||||||
import { IconLink } from '../../../design/IconLink'
|
import { IconLink } from '../../design/IconLink'
|
||||||
|
|
||||||
export interface GuildProps {
|
export interface GuildProps {
|
||||||
guild: GuildWithDefaultChannelId
|
guild: GuildWithDefaultChannelId
|
||||||
selected?: boolean
|
selected?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Guild: React.FC<GuildProps> = (props) => {
|
const GuildMemo: React.FC<GuildProps> = (props) => {
|
||||||
const { guild, selected } = props
|
const { guild, selected } = props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -34,3 +35,5 @@ export const Guild: React.FC<GuildProps> = (props) => {
|
|||||||
</IconLink>
|
</IconLink>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const Guild = memo(GuildMemo)
|
@ -1,18 +0,0 @@
|
|||||||
import { render } from '@testing-library/react'
|
|
||||||
|
|
||||||
import { Guild } from './Guild'
|
|
||||||
import { guildExample } from '../../../../cypress/fixtures/guilds/guild'
|
|
||||||
|
|
||||||
describe('<Guild />', () => {
|
|
||||||
it('should render successfully', () => {
|
|
||||||
const { baseElement } = render(
|
|
||||||
<Guild
|
|
||||||
guild={{
|
|
||||||
...guildExample,
|
|
||||||
defaultChannelId: 1
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
expect(baseElement).toBeTruthy()
|
|
||||||
})
|
|
||||||
})
|
|
@ -1 +0,0 @@
|
|||||||
export * from './Guild'
|
|
@ -2,16 +2,16 @@ import Image from 'next/image'
|
|||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import useTranslation from 'next-translate/useTranslation'
|
import useTranslation from 'next-translate/useTranslation'
|
||||||
import classNames from 'classnames'
|
import classNames from 'clsx'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
|
||||||
import { Emoji } from '../../../Emoji'
|
import { Emoji } from '../../Emoji'
|
||||||
import { ConfirmGuildJoin } from '../../ConfirmGuildJoin'
|
import { ConfirmPopup } from '../ConfirmPopup'
|
||||||
import {
|
import {
|
||||||
GuildPublic as GuildPublicType,
|
GuildPublic as GuildPublicType,
|
||||||
GuildWithDefaultChannelId
|
GuildWithDefaultChannelId
|
||||||
} from '../../../../models/Guild'
|
} from '../../../models/Guild'
|
||||||
import { useAuthentication } from '../../../../tools/authentication'
|
import { useAuthentication } from '../../../tools/authentication'
|
||||||
|
|
||||||
export interface GuildPublicProps {
|
export interface GuildPublicProps {
|
||||||
guild: GuildPublicType
|
guild: GuildPublicType
|
||||||
@ -40,7 +40,7 @@ export const GuildPublic: React.FC<GuildPublicProps> = (props) => {
|
|||||||
if (
|
if (
|
||||||
axios.isAxiosError(error) &&
|
axios.isAxiosError(error) &&
|
||||||
error.response?.status === 400 &&
|
error.response?.status === 400 &&
|
||||||
typeof error.response?.data.defaultChannelId === 'number'
|
typeof error?.response?.data.defaultChannelId === 'number'
|
||||||
) {
|
) {
|
||||||
const defaultChannelId = error.response.data.defaultChannelId as number
|
const defaultChannelId = error.response.data.defaultChannelId as number
|
||||||
await router.push(`/application/${guild.id}/${defaultChannelId}`)
|
await router.push(`/application/${guild.id}/${defaultChannelId}`)
|
||||||
@ -91,7 +91,8 @@ export const GuildPublic: React.FC<GuildPublicProps> = (props) => {
|
|||||||
{guild.membersCount} {t('application:members')}
|
{guild.membersCount} {t('application:members')}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<ConfirmGuildJoin
|
<ConfirmPopup
|
||||||
|
title={`${t('application:join-the-guild')} ?`}
|
||||||
className={classNames(
|
className={classNames(
|
||||||
'w-ful h-ful translate-x- absolute top-1/2 left-full flex h-full w-full -translate-y-1/2 flex-col items-center justify-center rounded-2xl transition-all',
|
'w-ful h-ful translate-x- absolute top-1/2 left-full flex h-full w-full -translate-y-1/2 flex-col items-center justify-center rounded-2xl transition-all',
|
||||||
{
|
{
|
@ -1 +0,0 @@
|
|||||||
export * from './GuildPublic'
|
|
@ -22,12 +22,15 @@ export const JoinGuildsPublic: React.FC = () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
authentication.socket.on('guilds', (data: SocketData<GuildPublicType>) => {
|
authentication?.socket?.on(
|
||||||
|
'guilds',
|
||||||
|
(data: SocketData<GuildPublicType>) => {
|
||||||
handleSocketData({ data, setItems })
|
handleSocketData({ data, setItems })
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
authentication.socket.off('guilds')
|
authentication?.socket?.off('guilds')
|
||||||
}
|
}
|
||||||
}, [authentication.socket, setItems])
|
}, [authentication.socket, setItems])
|
||||||
|
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
|
import { memo } from 'react'
|
||||||
import Image from 'next/image'
|
import Image from 'next/image'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
|
||||||
import { MemberWithPublicUser } from '../../../../models/Member'
|
import { MemberWithPublicUser } from '../../../models/Member'
|
||||||
|
import { Emoji } from '../../Emoji'
|
||||||
|
|
||||||
export interface MemberProps {
|
export interface MemberProps {
|
||||||
member: MemberWithPublicUser
|
member: MemberWithPublicUser
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Member: React.FC<MemberProps> = (props) => {
|
const MemberMemo: React.FC<MemberProps> = (props) => {
|
||||||
const { member } = props
|
const { member } = props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -29,8 +31,13 @@ export const Member: React.FC<MemberProps> = (props) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className='ml-5'>
|
<div className='ml-5'>
|
||||||
<p data-cy='member-user-name' className='truncate font-bold'>
|
<p data-cy='member-user-name' className='flex truncate font-bold'>
|
||||||
{member.user.name}
|
{member.user.name}
|
||||||
|
{member.isOwner && (
|
||||||
|
<span className='ml-4'>
|
||||||
|
<Emoji value=':crown:' size={18} />
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</p>
|
</p>
|
||||||
{member.user.status != null && member.user.status}
|
{member.user.status != null && member.user.status}
|
||||||
</div>
|
</div>
|
||||||
@ -39,3 +46,5 @@ export const Member: React.FC<MemberProps> = (props) => {
|
|||||||
</Link>
|
</Link>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const Member = memo(MemberMemo)
|
@ -1,11 +0,0 @@
|
|||||||
import { render } from '@testing-library/react'
|
|
||||||
|
|
||||||
import { Member } from './Member'
|
|
||||||
import { memberExampleComplete } from '../../../../cypress/fixtures/members/member'
|
|
||||||
|
|
||||||
describe('<Member />', () => {
|
|
||||||
it('should render successfully', () => {
|
|
||||||
const { baseElement } = render(<Member member={memberExampleComplete} />)
|
|
||||||
expect(baseElement).toBeTruthy()
|
|
||||||
})
|
|
||||||
})
|
|
@ -1 +0,0 @@
|
|||||||
export * from './Member'
|
|
@ -1,11 +1,16 @@
|
|||||||
|
import { useState, useRef } from 'react'
|
||||||
import Image from 'next/image'
|
import Image from 'next/image'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import date from 'date-and-time'
|
import date from 'date-and-time'
|
||||||
|
import TextareaAutosize from 'react-textarea-autosize'
|
||||||
|
import useTranslation from 'next-translate/useTranslation'
|
||||||
|
|
||||||
import { MessageWithMember } from '../../../../models/Message'
|
import { MessageWithMember } from '../../../../models/Message'
|
||||||
import { MessageText } from './MessageText'
|
import { MessageText } from './MessageText'
|
||||||
import { Loader } from '../../../design/Loader'
|
import { Loader } from '../../../design/Loader'
|
||||||
import { MessageFile } from './MessageFile'
|
import { MessageFile } from './MessageFile'
|
||||||
|
import { Emoji } from '../../../Emoji'
|
||||||
|
import { useAuthentication } from '../../../../tools/authentication'
|
||||||
|
|
||||||
export interface MessageProps {
|
export interface MessageProps {
|
||||||
message: MessageWithMember
|
message: MessageWithMember
|
||||||
@ -14,9 +19,60 @@ export interface MessageProps {
|
|||||||
export const Message: React.FC<MessageProps> = (props) => {
|
export const Message: React.FC<MessageProps> = (props) => {
|
||||||
const { message } = props
|
const { message } = props
|
||||||
|
|
||||||
|
const textareaReference = useRef<HTMLTextAreaElement>(null)
|
||||||
|
const [isEditing, setIsEditing] = useState(false)
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const { authentication, user } = useAuthentication()
|
||||||
|
|
||||||
|
const handleDeleteMessage = async (): Promise<void> => {
|
||||||
|
try {
|
||||||
|
await authentication.api.delete(`/messages/${message.id}`)
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleTextareaKeyDown: React.KeyboardEventHandler<HTMLFormElement> = (
|
||||||
|
event
|
||||||
|
) => {
|
||||||
|
if (event.key === 'Enter' && !event.shiftKey) {
|
||||||
|
event.preventDefault()
|
||||||
|
event.currentTarget.dispatchEvent(
|
||||||
|
new Event('submit', { cancelable: true, bubbles: true })
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleEdit = async (): Promise<void> => {
|
||||||
|
const newMessage = textareaReference.current?.value ?? message.value
|
||||||
|
if (
|
||||||
|
typeof newMessage === 'string' &&
|
||||||
|
newMessage.length > 0 &&
|
||||||
|
newMessage !== message.value
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
await authentication.api.put(`/messages/${message.id}`, {
|
||||||
|
value: newMessage
|
||||||
|
})
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
handleEditMode()
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleEditSubmit: React.FormEventHandler<HTMLFormElement> = async (
|
||||||
|
event
|
||||||
|
) => {
|
||||||
|
event.preventDefault()
|
||||||
|
await handleEdit()
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleEditMode = (): void => {
|
||||||
|
setIsEditing((oldIsEditing) => {
|
||||||
|
return !oldIsEditing
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className='flex p-4 transition hover:bg-gray-200 dark:hover:bg-gray-900'
|
className='group flex w-full p-4 transition hover:bg-gray-200 dark:hover:bg-gray-900'
|
||||||
data-cy={`message-${message.id}`}
|
data-cy={`message-${message.id}`}
|
||||||
>
|
>
|
||||||
<Link href={`/application/users/${message.member.user.id}`}>
|
<Link href={`/application/users/${message.member.user.id}`}>
|
||||||
@ -40,7 +96,7 @@ export const Message: React.FC<MessageProps> = (props) => {
|
|||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</Link>
|
</Link>
|
||||||
<div className='w-full'>
|
<div className='relative w-full whitespace-pre-wrap break-words break-all'>
|
||||||
<div className='flex w-max items-center'>
|
<div className='flex w-max items-center'>
|
||||||
<Link href={`/application/users/${message.member.user.id}`}>
|
<Link href={`/application/users/${message.member.user.id}`}>
|
||||||
<a>
|
<a>
|
||||||
@ -59,8 +115,58 @@ export const Message: React.FC<MessageProps> = (props) => {
|
|||||||
{date.format(new Date(message.createdAt), 'DD/MM/YYYY - HH:mm:ss')}
|
{date.format(new Date(message.createdAt), 'DD/MM/YYYY - HH:mm:ss')}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
{message.member.userId === user.id ? (
|
||||||
|
<div className='absolute right-6 -top-8 flex opacity-0 transition-opacity group-hover:opacity-100'>
|
||||||
{message.type === 'text' ? (
|
{message.type === 'text' ? (
|
||||||
|
<div
|
||||||
|
className='message-options rounded-l-lg border-l-slate-600'
|
||||||
|
title={t('application:edit')}
|
||||||
|
onClick={isEditing ? handleEdit : handleEditMode}
|
||||||
|
>
|
||||||
|
<Emoji
|
||||||
|
value={isEditing ? ':white_check_mark:' : ':pencil2:'}
|
||||||
|
size={18}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
<div
|
||||||
|
className='message-options rounded-r-lg border-r-slate-600'
|
||||||
|
title={t('application:delete')}
|
||||||
|
onClick={handleDeleteMessage}
|
||||||
|
>
|
||||||
|
<Emoji value=':wastebasket:' size={18} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
{message.type === 'text' ? (
|
||||||
|
<>
|
||||||
|
{isEditing ? (
|
||||||
|
<form
|
||||||
|
className='flex h-full w-full items-center'
|
||||||
|
onSubmit={handleEditSubmit}
|
||||||
|
onKeyDown={handleTextareaKeyDown}
|
||||||
|
>
|
||||||
|
<TextareaAutosize
|
||||||
|
className='scrollbar-firefox-support w-full resize-none bg-transparent p-2 tracking-wide outline-none'
|
||||||
|
placeholder={t('application:write-a-message')}
|
||||||
|
wrap='soft'
|
||||||
|
maxRows={6}
|
||||||
|
name='message'
|
||||||
|
defaultValue={message.value}
|
||||||
|
ref={textareaReference}
|
||||||
|
autoFocus
|
||||||
|
onFocus={(event) => {
|
||||||
|
event.currentTarget.setSelectionRange(
|
||||||
|
event.currentTarget.value.length,
|
||||||
|
event.currentTarget.value.length
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</form>
|
||||||
|
) : (
|
||||||
<MessageText message={message} />
|
<MessageText message={message} />
|
||||||
|
)}
|
||||||
|
</>
|
||||||
) : message.type === 'file' ? (
|
) : message.type === 'file' ? (
|
||||||
<MessageFile message={message} />
|
<MessageFile message={message} />
|
||||||
) : (
|
) : (
|
||||||
|
@ -4,6 +4,8 @@ import gfm from 'remark-gfm'
|
|||||||
import remarkBreaks from 'remark-breaks'
|
import remarkBreaks from 'remark-breaks'
|
||||||
import remarkMath from 'remark-math'
|
import remarkMath from 'remark-math'
|
||||||
import rehypeKatex from 'rehype-katex'
|
import rehypeKatex from 'rehype-katex'
|
||||||
|
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
|
||||||
|
import { vscDarkPlus } from 'react-syntax-highlighter/dist/cjs/styles/prism'
|
||||||
|
|
||||||
import 'katex/dist/katex.min.css'
|
import 'katex/dist/katex.min.css'
|
||||||
|
|
||||||
@ -25,7 +27,7 @@ export const MessageText: React.FC<MessageContentProps> = (props) => {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<p>
|
<p>
|
||||||
<Emoji value={message.value} size={40} />
|
<Emoji value={message.value} size={40} tooltip />
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
@ -39,8 +41,34 @@ export const MessageText: React.FC<MessageContentProps> = (props) => {
|
|||||||
rehypePlugins={[[emojiPlugin], [rehypeKatex]]}
|
rehypePlugins={[[emojiPlugin], [rehypeKatex]]}
|
||||||
linkTarget='_blank'
|
linkTarget='_blank'
|
||||||
components={{
|
components={{
|
||||||
|
a: (props) => {
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
className='text-green-800 hover:underline dark:text-green-400'
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
},
|
||||||
emoji: (props) => {
|
emoji: (props) => {
|
||||||
return <Emoji value={props.value} size={20} />
|
return <Emoji value={props.value} size={20} tooltip />
|
||||||
|
},
|
||||||
|
code: (properties) => {
|
||||||
|
const { inline, className, children, ...props } = properties
|
||||||
|
const match = /language-(\w+)/.exec(className ?? '')
|
||||||
|
return !(inline as boolean) && match != null ? (
|
||||||
|
<SyntaxHighlighter
|
||||||
|
style={vscDarkPlus as any}
|
||||||
|
language={match[1]}
|
||||||
|
PreTag='div'
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{String(children).replace(/\n$/, '')}
|
||||||
|
</SyntaxHighlighter>
|
||||||
|
) : (
|
||||||
|
<code className={className} {...props}>
|
||||||
|
{children}
|
||||||
|
</code>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
import { render } from '@testing-library/react'
|
|
||||||
|
|
||||||
import { PopupGuild } from './PopupGuild'
|
|
||||||
|
|
||||||
describe('<PopupGuild />', () => {
|
|
||||||
it('should render successfully', () => {
|
|
||||||
const { baseElement } = render(<PopupGuild />)
|
|
||||||
expect(baseElement).toBeTruthy()
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,9 +1,10 @@
|
|||||||
import useTranslation from 'next-translate/useTranslation'
|
import useTranslation from 'next-translate/useTranslation'
|
||||||
import { PlusSmIcon, ArrowDownIcon } from '@heroicons/react/solid'
|
import { PlusSmIcon, ArrowDownIcon } from '@heroicons/react/solid'
|
||||||
import classNames from 'classnames'
|
import classNames from 'clsx'
|
||||||
import Image from 'next/image'
|
import Image from 'next/image'
|
||||||
|
|
||||||
import { PopupGuildCard } from './PopupGuildCard/PopupGuildCard'
|
import { PopupGuildCard } from './PopupGuildCard'
|
||||||
|
|
||||||
export interface PopupGuildProps {
|
export interface PopupGuildProps {
|
||||||
className?: string
|
className?: string
|
||||||
}
|
}
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
import { render } from '@testing-library/react'
|
|
||||||
import { PlusSmIcon } from '@heroicons/react/solid'
|
|
||||||
import Image from 'next/image'
|
|
||||||
|
|
||||||
import { PopupGuildCard } from './PopupGuildCard'
|
|
||||||
|
|
||||||
describe('<PopupGuildCard />', () => {
|
|
||||||
it('should render successfully', () => {
|
|
||||||
const { baseElement } = render(
|
|
||||||
<PopupGuildCard
|
|
||||||
image={
|
|
||||||
<Image
|
|
||||||
quality={100}
|
|
||||||
src='/images/svg/design/create-server.svg'
|
|
||||||
alt=''
|
|
||||||
width={230}
|
|
||||||
height={230}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
description='Create your own guild and manage everything within a few clicks !'
|
|
||||||
link={{
|
|
||||||
icon: <PlusSmIcon className='mr-2 h-8 w-8' />,
|
|
||||||
text: 'Create a server',
|
|
||||||
href: '/application/guilds/create'
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
expect(baseElement).toBeTruthy()
|
|
||||||
})
|
|
||||||
})
|
|
@ -1 +0,0 @@
|
|||||||
export * from './PopupGuildCard'
|
|
@ -1,7 +1,7 @@
|
|||||||
import { useState, useRef } from 'react'
|
import { useState, useRef } from 'react'
|
||||||
import useTranslation from 'next-translate/useTranslation'
|
import useTranslation from 'next-translate/useTranslation'
|
||||||
import TextareaAutosize from 'react-textarea-autosize'
|
import TextareaAutosize from 'react-textarea-autosize'
|
||||||
import classNames from 'classnames'
|
import classNames from 'clsx'
|
||||||
|
|
||||||
import { GuildsChannelsPath } from '..'
|
import { GuildsChannelsPath } from '..'
|
||||||
import { useAuthentication } from '../../../tools/authentication'
|
import { useAuthentication } from '../../../tools/authentication'
|
||||||
@ -96,7 +96,7 @@ export const SendMessage: React.FC<SendMessageProps> = (props) => {
|
|||||||
onKeyDown={handleTextareaKeyDown}
|
onKeyDown={handleTextareaKeyDown}
|
||||||
>
|
>
|
||||||
<TextareaAutosize
|
<TextareaAutosize
|
||||||
className='scrollbar-firefox-support my-2 w-full resize-none bg-transparent p-2 px-6 font-paragraph tracking-wide outline-none'
|
className='scrollbar-firefox-support my-2 w-full resize-none bg-transparent p-2 px-6 tracking-wide outline-none'
|
||||||
placeholder={t('application:write-a-message')}
|
placeholder={t('application:write-a-message')}
|
||||||
wrap='soft'
|
wrap='soft'
|
||||||
maxRows={6}
|
maxRows={6}
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
import { render } from '@testing-library/react'
|
|
||||||
|
|
||||||
import { Sidebar } from './Sidebar'
|
|
||||||
|
|
||||||
describe('<Sidebar />', () => {
|
|
||||||
it('should render successfully', () => {
|
|
||||||
const { baseElement } = render(
|
|
||||||
<Sidebar direction='left' visible={true} isMobile={false} />
|
|
||||||
)
|
|
||||||
expect(baseElement).toBeTruthy()
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,4 +1,4 @@
|
|||||||
import classNames from 'classnames'
|
import classNames from 'clsx'
|
||||||
|
|
||||||
import { ApplicationProps } from '..'
|
import { ApplicationProps } from '..'
|
||||||
|
|
||||||
@ -11,7 +11,9 @@ export interface SidebarProps {
|
|||||||
isMobile: boolean
|
isMobile: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Sidebar: React.FC<SidebarProps> = (props) => {
|
export const Sidebar: React.FC<React.PropsWithChildren<SidebarProps>> = (
|
||||||
|
props
|
||||||
|
) => {
|
||||||
const { direction, visible, children, path, isMobile } = props
|
const { direction, visible, children, path, isMobile } = props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
import { render } from '@testing-library/react'
|
|
||||||
|
|
||||||
import {
|
|
||||||
guildExample,
|
|
||||||
guildExample2
|
|
||||||
} from '../../../cypress/fixtures/guilds/guild'
|
|
||||||
import {
|
|
||||||
userExample,
|
|
||||||
userSettingsExample
|
|
||||||
} from '../../../cypress/fixtures/users/user'
|
|
||||||
import { UserProfile } from './UserProfile'
|
|
||||||
|
|
||||||
describe('<UserProfile />', () => {
|
|
||||||
it('should render successfully', () => {
|
|
||||||
const { baseElement } = render(
|
|
||||||
<UserProfile
|
|
||||||
user={{ ...userExample, settings: userSettingsExample }}
|
|
||||||
guilds={[guildExample, guildExample2]}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
expect(baseElement).toBeTruthy()
|
|
||||||
})
|
|
||||||
})
|
|
@ -16,11 +16,12 @@ export const UserProfile: React.FC<UserProfileProps> = (props) => {
|
|||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<div className='relative flex h-full flex-col items-center justify-center'>
|
<div className='relative flex h-full flex-col items-center justify-center'>
|
||||||
<div className='transition'>
|
<div className='transition'>
|
||||||
<div className='max-w-[1000px] px-12'>
|
<div className='max-w-[1000px] px-12'>
|
||||||
<div className='flex items-center justify-between'>
|
<div className='flex items-center justify-between'>
|
||||||
<div className='flex w-max items-center'>
|
<div className='flex w-max flex-col items-center gap-7 md:flex-row'>
|
||||||
<div className='relative flex items-center justify-center overflow-hidden rounded-full shadow-lg transition-all'>
|
<div className='relative flex items-center justify-center overflow-hidden rounded-full shadow-lg transition-all'>
|
||||||
<Image
|
<Image
|
||||||
quality={100}
|
quality={100}
|
||||||
@ -70,6 +71,8 @@ export const UserProfile: React.FC<UserProfileProps> = (props) => {
|
|||||||
<p className='font-bold'>
|
<p className='font-bold'>
|
||||||
{t('application:website')}:{' '}
|
{t('application:website')}:{' '}
|
||||||
<a
|
<a
|
||||||
|
target='_blank'
|
||||||
|
rel='noreferrer'
|
||||||
href={user.website}
|
href={user.website}
|
||||||
className='relative ml-2 font-normal tracking-wide no-underline opacity-80 transition-all after:absolute after:left-0 after:bottom-[-2px] after:h-[1px] after:w-0 after:bg-black after:transition-all hover:opacity-100 hover:after:w-full dark:after:bg-white'
|
className='relative ml-2 font-normal tracking-wide no-underline opacity-80 transition-all after:absolute after:left-0 after:bottom-[-2px] after:h-[1px] after:w-0 after:bg-black after:transition-all hover:opacity-100 hover:after:w-full dark:after:bg-white'
|
||||||
>
|
>
|
||||||
@ -89,11 +92,20 @@ export const UserProfile: React.FC<UserProfileProps> = (props) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className='mt-7'>
|
{user.biography != null && (
|
||||||
{user.biography != null && <p>{user.biography}</p>}
|
<div className='mt-7 text-center'>
|
||||||
</div>
|
<p>{user.biography}</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<style jsx global>{`
|
||||||
|
#application-page-content {
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
|
`}</style>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import Image from 'next/image'
|
import Image from 'next/image'
|
||||||
import useTranslation from 'next-translate/useTranslation'
|
import useTranslation from 'next-translate/useTranslation'
|
||||||
import { useState, useMemo } from 'react'
|
import { useState, useMemo } from 'react'
|
||||||
import { Form } from 'react-component-form'
|
import { Form, useForm } from 'react-component-form'
|
||||||
import { EyeIcon, PhotographIcon } from '@heroicons/react/solid'
|
import { EyeIcon, PhotographIcon } from '@heroicons/react/solid'
|
||||||
import { Type } from '@sinclair/typebox'
|
import { Type } from '@sinclair/typebox'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
import type { HandleUseFormCallback } from 'react-component-form'
|
||||||
|
|
||||||
import { Input } from '../../design/Input'
|
import { Input } from '../../design/Input'
|
||||||
import { Checkbox } from '../../design/Checkbox'
|
import { Checkbox } from '../../design/Checkbox'
|
||||||
@ -16,10 +17,20 @@ import { Language } from '../../Header/Language'
|
|||||||
import { useAuthentication } from '../../../tools/authentication'
|
import { useAuthentication } from '../../../tools/authentication'
|
||||||
import { Button } from '../../design/Button'
|
import { Button } from '../../design/Button'
|
||||||
import { FormState } from '../../design/FormState'
|
import { FormState } from '../../design/FormState'
|
||||||
import { useForm, HandleSubmitCallback } from '../../../hooks/useForm'
|
|
||||||
import { userSchema } from '../../../models/User'
|
import { userSchema } from '../../../models/User'
|
||||||
import { userSettingsSchema } from '../../../models/UserSettings'
|
import { userSettingsSchema } from '../../../models/UserSettings'
|
||||||
import { ProviderOAuth, providers } from '../../../models/OAuth'
|
import { ProviderOAuth, providers } from '../../../models/OAuth'
|
||||||
|
import { useFormTranslation } from '../../../hooks/useFormTranslation'
|
||||||
|
|
||||||
|
const schema = {
|
||||||
|
name: userSchema.name,
|
||||||
|
status: Type.Optional(userSchema.status),
|
||||||
|
email: Type.Optional(Type.Union([userSchema.email, Type.Null()])),
|
||||||
|
website: Type.Optional(userSchema.website),
|
||||||
|
biography: Type.Optional(userSchema.biography),
|
||||||
|
isPublicGuilds: userSettingsSchema.isPublicGuilds,
|
||||||
|
isPublicEmail: userSettingsSchema.isPublicEmail
|
||||||
|
}
|
||||||
|
|
||||||
export const UserSettings: React.FC = () => {
|
export const UserSettings: React.FC = () => {
|
||||||
const { user, setUser, authentication } = useAuthentication()
|
const { user, setUser, authentication } = useAuthentication()
|
||||||
@ -35,32 +46,20 @@ export const UserSettings: React.FC = () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
handleUseForm,
|
||||||
fetchState,
|
fetchState,
|
||||||
setFetchState,
|
setFetchState,
|
||||||
message,
|
message,
|
||||||
setMessageTranslationKey,
|
setMessage,
|
||||||
errors,
|
errors
|
||||||
getErrorTranslation,
|
} = useForm(schema)
|
||||||
handleSubmit
|
const { getFirstErrorTranslation } = useFormTranslation()
|
||||||
} = useForm({
|
|
||||||
validateSchema: {
|
|
||||||
name: userSchema.name,
|
|
||||||
status: Type.Optional(userSchema.status),
|
|
||||||
email: Type.Optional(Type.Union([userSchema.email, Type.Null()])),
|
|
||||||
website: Type.Optional(userSchema.website),
|
|
||||||
biography: Type.Optional(userSchema.biography),
|
|
||||||
isPublicGuilds: userSettingsSchema.isPublicGuilds,
|
|
||||||
isPublicEmail: userSettingsSchema.isPublicEmail
|
|
||||||
},
|
|
||||||
replaceEmptyStringToNull: true,
|
|
||||||
resetOnSuccess: false
|
|
||||||
})
|
|
||||||
|
|
||||||
const hasAllProviders = useMemo(() => {
|
const hasAllProviders = useMemo(() => {
|
||||||
return providers.every((provider) => user.strategies.includes(provider))
|
return providers.every((provider) => user.strategies.includes(provider))
|
||||||
}, [user.strategies])
|
}, [user.strategies])
|
||||||
|
|
||||||
const onSubmit: HandleSubmitCallback = async (formData) => {
|
const onSubmit: HandleUseFormCallback<typeof schema> = async (formData) => {
|
||||||
try {
|
try {
|
||||||
const { isPublicGuilds, isPublicEmail, ...userData } = formData
|
const { isPublicGuilds, isPublicEmail, ...userData } = formData
|
||||||
const userSettings = { isPublicEmail, isPublicGuilds }
|
const userSettings = { isPublicEmail, isPublicGuilds }
|
||||||
@ -68,7 +67,7 @@ export const UserSettings: React.FC = () => {
|
|||||||
`/users/current?redirectURI=${window.location.origin}/authentication/signin`,
|
`/users/current?redirectURI=${window.location.origin}/authentication/signin`,
|
||||||
userData
|
userData
|
||||||
)
|
)
|
||||||
setInputValues(formData as any)
|
setInputValues(formData as unknown as any)
|
||||||
const hasEmailChanged = user.email !== userCurrentData.user.email
|
const hasEmailChanged = user.email !== userCurrentData.user.email
|
||||||
if (hasEmailChanged) {
|
if (hasEmailChanged) {
|
||||||
return {
|
return {
|
||||||
@ -165,19 +164,19 @@ export const UserSettings: React.FC = () => {
|
|||||||
setFetchState('idle')
|
setFetchState('idle')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setFetchState('error')
|
setFetchState('error')
|
||||||
setMessageTranslationKey('errors:server-error')
|
setMessage('errors:server-error')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSignout = async (): Promise<void> => {
|
const handleSignout = async (): Promise<void> => {
|
||||||
try {
|
|
||||||
setFetchState('loading')
|
setFetchState('loading')
|
||||||
await authentication.signoutServerSide()
|
await authentication.signoutServerSide()
|
||||||
} catch (error) {
|
|
||||||
setFetchState('error')
|
|
||||||
setMessageTranslationKey('errors:server-error')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleSignoutAllDevices = async (): Promise<void> => {
|
||||||
|
setFetchState('loading')
|
||||||
|
await authentication.signoutAllDevicesServerSide()
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleDeletionProvider = (
|
const handleDeletionProvider = (
|
||||||
@ -195,10 +194,10 @@ export const UserSettings: React.FC = () => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
setMessageTranslationKey('application:success-deleted-provider')
|
setMessage('application:success-deleted-provider')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setFetchState('error')
|
setFetchState('error')
|
||||||
setMessageTranslationKey('errors:server-error')
|
setMessage('errors:server-error')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -217,7 +216,7 @@ export const UserSettings: React.FC = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Form
|
<Form
|
||||||
onSubmit={handleSubmit(onSubmit)}
|
onSubmit={handleUseForm(onSubmit)}
|
||||||
className='my-auto flex flex-col items-center justify-center py-12 lg:min-w-[875px]'
|
className='my-auto flex flex-col items-center justify-center py-12 lg:min-w-[875px]'
|
||||||
>
|
>
|
||||||
<div className='flex w-full flex-col items-center justify-center sm:w-fit lg:flex-row'>
|
<div className='flex w-full flex-col items-center justify-center sm:w-fit lg:flex-row'>
|
||||||
@ -257,7 +256,7 @@ export const UserSettings: React.FC = () => {
|
|||||||
className='!mt-0'
|
className='!mt-0'
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
value={inputValues.name ?? ''}
|
value={inputValues.name ?? ''}
|
||||||
error={getErrorTranslation(errors.name)}
|
error={getFirstErrorTranslation(errors.name)}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
name='status'
|
name='status'
|
||||||
@ -266,7 +265,7 @@ export const UserSettings: React.FC = () => {
|
|||||||
className='!mt-4'
|
className='!mt-4'
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
value={inputValues.status ?? ''}
|
value={inputValues.status ?? ''}
|
||||||
error={getErrorTranslation(errors.status)}
|
error={getFirstErrorTranslation(errors.status)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -279,7 +278,7 @@ export const UserSettings: React.FC = () => {
|
|||||||
placeholder='Email'
|
placeholder='Email'
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
value={inputValues.email ?? ''}
|
value={inputValues.email ?? ''}
|
||||||
error={getErrorTranslation(errors.email)}
|
error={getFirstErrorTranslation(errors.email)}
|
||||||
/>
|
/>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
name='isPublicEmail'
|
name='isPublicEmail'
|
||||||
@ -294,7 +293,7 @@ export const UserSettings: React.FC = () => {
|
|||||||
placeholder={t('application:website')}
|
placeholder={t('application:website')}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
value={inputValues.website ?? ''}
|
value={inputValues.website ?? ''}
|
||||||
error={getErrorTranslation(errors.website)}
|
error={getFirstErrorTranslation(errors.website)}
|
||||||
/>
|
/>
|
||||||
<Textarea
|
<Textarea
|
||||||
name='biography'
|
name='biography'
|
||||||
@ -376,7 +375,15 @@ export const UserSettings: React.FC = () => {
|
|||||||
{t('application:signout')}
|
{t('application:signout')}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<FormState state={fetchState} message={message} />
|
<div className='mt-4'>
|
||||||
|
<Button type='button' color='red' onClick={handleSignoutAllDevices}>
|
||||||
|
{t('application:signout-all-devices')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<FormState
|
||||||
|
state={fetchState}
|
||||||
|
message={message != null ? t(message) : undefined}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
)
|
)
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
|
import { useMemo } from 'react'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import useTranslation from 'next-translate/useTranslation'
|
import useTranslation from 'next-translate/useTranslation'
|
||||||
import { useTheme } from 'next-themes'
|
import { useTheme } from 'next-themes'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
import { useForm } from 'react-component-form'
|
||||||
|
import type { HandleUseFormCallback } from 'react-component-form'
|
||||||
|
|
||||||
import { Main } from '../design/Main'
|
import { Main } from '../design/Main'
|
||||||
import { Input } from '../design/Input'
|
import { Input } from '../design/Input'
|
||||||
@ -15,8 +18,8 @@ import {
|
|||||||
Tokens,
|
Tokens,
|
||||||
Authentication as AuthenticationClass
|
Authentication as AuthenticationClass
|
||||||
} from '../../tools/authentication'
|
} from '../../tools/authentication'
|
||||||
import { useForm, HandleSubmitCallback } from '../../hooks/useForm'
|
|
||||||
import { AuthenticationSocialMedia } from './AuthenticationSocialMedia'
|
import { AuthenticationSocialMedia } from './AuthenticationSocialMedia'
|
||||||
|
import { useFormTranslation } from '../../hooks/useFormTranslation'
|
||||||
|
|
||||||
export interface AuthenticationProps {
|
export interface AuthenticationProps {
|
||||||
mode: 'signup' | 'signin'
|
mode: 'signup' | 'signin'
|
||||||
@ -29,23 +32,28 @@ export const Authentication: React.FC<AuthenticationProps> = (props) => {
|
|||||||
const { lang, t } = useTranslation()
|
const { lang, t } = useTranslation()
|
||||||
const { theme } = useTheme()
|
const { theme } = useTheme()
|
||||||
|
|
||||||
const { errors, fetchState, message, getErrorTranslation, handleSubmit } =
|
const schema = useMemo(() => {
|
||||||
useForm({
|
return {
|
||||||
validateSchema: {
|
|
||||||
...(mode === 'signup' && { name: userSchema.name }),
|
...(mode === 'signup' && { name: userSchema.name }),
|
||||||
email: userSchema.email,
|
email: userSchema.email,
|
||||||
password: userSchema.password
|
password: userSchema.password
|
||||||
},
|
}
|
||||||
resetOnSuccess: true
|
}, [mode])
|
||||||
})
|
|
||||||
|
|
||||||
const onSubmit: HandleSubmitCallback = async (formData) => {
|
const { handleUseForm, errors, fetchState, message } = useForm(schema)
|
||||||
|
const { getFirstErrorTranslation } = useFormTranslation()
|
||||||
|
|
||||||
|
const onSubmit: HandleUseFormCallback<typeof schema> = async (
|
||||||
|
formData,
|
||||||
|
formElement
|
||||||
|
) => {
|
||||||
if (mode === 'signup') {
|
if (mode === 'signup') {
|
||||||
try {
|
try {
|
||||||
await api.post(
|
await api.post(
|
||||||
`/users/signup?redirectURI=${window.location.origin}/authentication/signin`,
|
`/users/signup?redirectURI=${window.location.origin}/authentication/signin`,
|
||||||
{ ...formData, language: lang, theme }
|
{ ...formData, language: lang, theme }
|
||||||
)
|
)
|
||||||
|
formElement.reset()
|
||||||
return {
|
return {
|
||||||
type: 'success',
|
type: 'success',
|
||||||
value: 'authentication:success-signup'
|
value: 'authentication:success-signup'
|
||||||
@ -72,7 +80,7 @@ export const Authentication: React.FC<AuthenticationProps> = (props) => {
|
|||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
const { data } = await api.post<Tokens>('/users/signin', formData)
|
const { data } = await api.post<Tokens>('/users/signin', formData)
|
||||||
const authentication = new AuthenticationClass(data)
|
const authentication = new AuthenticationClass(data, true)
|
||||||
authentication.signin()
|
authentication.signin()
|
||||||
await router.push('/application')
|
await router.push('/application')
|
||||||
return null
|
return null
|
||||||
@ -97,14 +105,14 @@ export const Authentication: React.FC<AuthenticationProps> = (props) => {
|
|||||||
<div className='pt-8 text-center font-paragraph text-lg'>
|
<div className='pt-8 text-center font-paragraph text-lg'>
|
||||||
{t('authentication:or')}
|
{t('authentication:or')}
|
||||||
</div>
|
</div>
|
||||||
<AuthenticationForm onSubmit={handleSubmit(onSubmit)}>
|
<AuthenticationForm onSubmit={handleUseForm(onSubmit)}>
|
||||||
{mode === 'signup' && (
|
{mode === 'signup' && (
|
||||||
<Input
|
<Input
|
||||||
type='text'
|
type='text'
|
||||||
placeholder={t('common:name')}
|
placeholder={t('common:name')}
|
||||||
name='name'
|
name='name'
|
||||||
label={t('common:name')}
|
label={t('common:name')}
|
||||||
error={getErrorTranslation(errors.name)}
|
error={getFirstErrorTranslation(errors.name)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<Input
|
<Input
|
||||||
@ -112,7 +120,7 @@ export const Authentication: React.FC<AuthenticationProps> = (props) => {
|
|||||||
placeholder='Email'
|
placeholder='Email'
|
||||||
name='email'
|
name='email'
|
||||||
label='Email'
|
label='Email'
|
||||||
error={getErrorTranslation(errors.email)}
|
error={getFirstErrorTranslation(errors.email)}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
type='password'
|
type='password'
|
||||||
@ -120,7 +128,7 @@ export const Authentication: React.FC<AuthenticationProps> = (props) => {
|
|||||||
name='password'
|
name='password'
|
||||||
label={t('authentication:password')}
|
label={t('authentication:password')}
|
||||||
showForgotPassword={mode === 'signin'}
|
showForgotPassword={mode === 'signin'}
|
||||||
error={getErrorTranslation(errors.password)}
|
error={getFirstErrorTranslation(errors.password)}
|
||||||
/>
|
/>
|
||||||
<Button data-cy='submit' className='mt-6 w-full' type='submit'>
|
<Button data-cy='submit' className='mt-6 w-full' type='submit'>
|
||||||
{t('authentication:submit')}
|
{t('authentication:submit')}
|
||||||
@ -141,7 +149,11 @@ export const Authentication: React.FC<AuthenticationProps> = (props) => {
|
|||||||
</Link>
|
</Link>
|
||||||
</p>
|
</p>
|
||||||
</AuthenticationForm>
|
</AuthenticationForm>
|
||||||
<FormState id='message' state={fetchState} message={message} />
|
<FormState
|
||||||
|
id='message'
|
||||||
|
state={fetchState}
|
||||||
|
message={message != null ? t(message) : undefined}
|
||||||
|
/>
|
||||||
</Main>
|
</Main>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import classNames from 'classnames'
|
import classNames from 'clsx'
|
||||||
import { Form, FormProps } from 'react-component-form'
|
import { Form, FormProps } from 'react-component-form'
|
||||||
|
|
||||||
export const AuthenticationForm: React.FC<FormProps> = (props) => {
|
export const AuthenticationForm: React.FC<FormProps> = (props) => {
|
||||||
|
@ -24,7 +24,7 @@ export const AuthenticationSocialMedia: React.FC = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const data = router.query
|
const data = router.query
|
||||||
if (isTokens(data)) {
|
if (isTokens(data)) {
|
||||||
const authentication = new Authentication(data)
|
const authentication = new Authentication(data, true)
|
||||||
authentication.signin()
|
authentication.signin()
|
||||||
router.push('/application').catch(() => {})
|
router.push('/application').catch(() => {})
|
||||||
}
|
}
|
||||||
|
@ -5,17 +5,18 @@ import { EMOJI_SET } from './emojiPlugin'
|
|||||||
export interface EmojiProps {
|
export interface EmojiProps {
|
||||||
value: string
|
value: string
|
||||||
size: number
|
size: number
|
||||||
|
tooltip?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Emoji: React.FC<EmojiProps> = (props) => {
|
export const Emoji: React.FC<EmojiProps> = (props) => {
|
||||||
const { value, size } = props
|
const { value, size, tooltip = false } = props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<EmojiMart
|
<EmojiMart
|
||||||
set={EMOJI_SET}
|
set={EMOJI_SET}
|
||||||
emoji={value}
|
emoji={value}
|
||||||
size={size}
|
size={size}
|
||||||
tooltip
|
tooltip={tooltip}
|
||||||
fallback={() => {
|
fallback={() => {
|
||||||
return <>{value}</>
|
return <>{value}</>
|
||||||
}}
|
}}
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
import { isStringWithOnlyOneEmoji } from './isStringWithOnlyOneEmoji'
|
|
||||||
|
|
||||||
describe('components/Emoji/isStringWithOnlyOneEmoji', () => {
|
|
||||||
it('returns true with a string with only one emoji', () => {
|
|
||||||
expect(isStringWithOnlyOneEmoji(':wave:')).toBeTruthy()
|
|
||||||
expect(isStringWithOnlyOneEmoji(':smile:')).toBeTruthy()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns false with a string with multiple emoji or with text', () => {
|
|
||||||
expect(isStringWithOnlyOneEmoji(':wave: :smile:')).toBeFalsy()
|
|
||||||
expect(isStringWithOnlyOneEmoji(':wave: some text')).toBeFalsy()
|
|
||||||
expect(isStringWithOnlyOneEmoji('some text :wave:')).toBeFalsy()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns false with a string without emoji', () => {
|
|
||||||
expect(isStringWithOnlyOneEmoji('some text')).toBeFalsy()
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,15 +0,0 @@
|
|||||||
import { render } from '@testing-library/react'
|
|
||||||
|
|
||||||
import { ErrorPage } from '.'
|
|
||||||
|
|
||||||
describe('<ErrorPage />', () => {
|
|
||||||
it('should render the message and statusCode', () => {
|
|
||||||
const messageContent = 'message content'
|
|
||||||
const statusCode = 404
|
|
||||||
const { getByText } = render(
|
|
||||||
<ErrorPage statusCode={statusCode} message={messageContent} />
|
|
||||||
)
|
|
||||||
expect(getByText(messageContent)).toBeInTheDocument()
|
|
||||||
expect(getByText(statusCode)).toBeInTheDocument()
|
|
||||||
})
|
|
||||||
})
|
|
@ -1 +0,0 @@
|
|||||||
export * from './ErrorPage'
|
|
@ -1,16 +0,0 @@
|
|||||||
import { render } from '@testing-library/react'
|
|
||||||
|
|
||||||
import { Footer } from '.'
|
|
||||||
|
|
||||||
describe('<Footer />', () => {
|
|
||||||
it('should render with appropriate link tag version', () => {
|
|
||||||
const version = '1.0.0'
|
|
||||||
const { getByText } = render(<Footer version={version} />)
|
|
||||||
const versionLink = getByText(`website v${version}`) as HTMLAnchorElement
|
|
||||||
expect(getByText('Thream')).toBeInTheDocument()
|
|
||||||
expect(versionLink).toBeInTheDocument()
|
|
||||||
expect(versionLink.href).toEqual(
|
|
||||||
`https://github.com/Thream/website/releases/tag/v${version}`
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
@ -8,6 +8,7 @@ export const VersionLink: React.FC<VersionLinkProps> = (props) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<a
|
<a
|
||||||
|
data-cy={`version-link-${repository}`}
|
||||||
className='text-green-800 hover:underline dark:text-green-400'
|
className='text-green-800 hover:underline dark:text-green-400'
|
||||||
href={`https://github.com/Thream/${repository}/releases/tag/v${version}`}
|
href={`https://github.com/Thream/${repository}/releases/tag/v${version}`}
|
||||||
target='_blank'
|
target='_blank'
|
||||||
|
@ -13,7 +13,7 @@ export const Head: React.FC<HeadProps> = (props) => {
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
title = 'Thream',
|
title = 'Thream',
|
||||||
image = '/images/icons/96x96.png',
|
image = 'https://thream.divlo.fr/images/icons/128x128.png',
|
||||||
description = t('common:description'),
|
description = t('common:description'),
|
||||||
url = 'https://thream.divlo.fr/'
|
url = 'https://thream.divlo.fr/'
|
||||||
} = props
|
} = props
|
||||||
@ -42,7 +42,7 @@ export const Head: React.FC<HeadProps> = (props) => {
|
|||||||
<meta name='twitter:card' content='summary' />
|
<meta name='twitter:card' content='summary' />
|
||||||
<meta name='twitter:description' content={description} />
|
<meta name='twitter:description' content={description} />
|
||||||
<meta name='twitter:title' content={title} />
|
<meta name='twitter:title' content={title} />
|
||||||
<meta name='twitter:image:src' content={image} />
|
<meta name='twitter:image' content={image} />
|
||||||
|
|
||||||
{/* PWA Data */}
|
{/* PWA Data */}
|
||||||
<link rel='manifest' href='/manifest.json' />
|
<link rel='manifest' href='/manifest.json' />
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
import { render } from '@testing-library/react'
|
|
||||||
|
|
||||||
import { Header } from '.'
|
|
||||||
|
|
||||||
describe('<Header />', () => {
|
|
||||||
it('should render', () => {
|
|
||||||
const { getByText } = render(<Header />)
|
|
||||||
expect(getByText('Thream')).toBeInTheDocument()
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,11 +1,12 @@
|
|||||||
import { useCallback, useEffect, useState } from 'react'
|
import { useCallback, useState, useRef } from 'react'
|
||||||
import useTranslation from 'next-translate/useTranslation'
|
import useTranslation from 'next-translate/useTranslation'
|
||||||
import setLanguage from 'next-translate/setLanguage'
|
import setLanguage from 'next-translate/setLanguage'
|
||||||
import classNames from 'classnames'
|
import classNames from 'clsx'
|
||||||
|
|
||||||
|
import i18n from '../../../i18n.json'
|
||||||
import { Arrow } from './Arrow'
|
import { Arrow } from './Arrow'
|
||||||
import { LanguageFlag } from './LanguageFlag'
|
import { LanguageFlag } from './LanguageFlag'
|
||||||
import i18n from '../../../i18n.json'
|
import { useClickOutsideAlerter } from '../../../hooks/useClickOutsideAlerter'
|
||||||
|
|
||||||
export interface LanguageProps {
|
export interface LanguageProps {
|
||||||
className?: string
|
className?: string
|
||||||
@ -15,22 +16,13 @@ export const Language: React.FC<LanguageProps> = (props) => {
|
|||||||
const { className } = props
|
const { className } = props
|
||||||
const { lang: currentLanguage } = useTranslation()
|
const { lang: currentLanguage } = useTranslation()
|
||||||
const [hiddenMenu, setHiddenMenu] = useState(true)
|
const [hiddenMenu, setHiddenMenu] = useState(true)
|
||||||
|
const languageClickRef = useRef<HTMLDivElement | null>(null)
|
||||||
|
|
||||||
const handleHiddenMenu = useCallback(() => {
|
const handleHiddenMenu = useCallback(() => {
|
||||||
setHiddenMenu(!hiddenMenu)
|
setHiddenMenu((oldHiddenMenu) => !oldHiddenMenu)
|
||||||
}, [hiddenMenu])
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useClickOutsideAlerter(languageClickRef, () => setHiddenMenu(true))
|
||||||
if (!hiddenMenu) {
|
|
||||||
window.document.addEventListener('click', handleHiddenMenu)
|
|
||||||
} else {
|
|
||||||
window.document.removeEventListener('click', handleHiddenMenu)
|
|
||||||
}
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
window.document.removeEventListener('click', handleHiddenMenu)
|
|
||||||
}
|
|
||||||
}, [hiddenMenu, handleHiddenMenu])
|
|
||||||
|
|
||||||
const handleLanguage = async (language: string): Promise<void> => {
|
const handleLanguage = async (language: string): Promise<void> => {
|
||||||
await setLanguage(language)
|
await setLanguage(language)
|
||||||
@ -38,7 +30,10 @@ export const Language: React.FC<LanguageProps> = (props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='relative flex cursor-pointer flex-col items-center justify-center'>
|
<div
|
||||||
|
className='relative flex cursor-pointer flex-col items-center justify-center'
|
||||||
|
ref={languageClickRef}
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
data-cy='language-click'
|
data-cy='language-click'
|
||||||
className='mr-5 flex items-center'
|
className='mr-5 flex items-center'
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
export const ScrollableBody: React.FC = (props) => {
|
export const ScrollableBody: React.FC<React.PropsWithChildren<{}>> = (
|
||||||
|
props
|
||||||
|
) => {
|
||||||
const { children } = props
|
const { children } = props
|
||||||
|
|
||||||
return (
|
return (
|
@ -1,10 +0,0 @@
|
|||||||
import { render } from '@testing-library/react'
|
|
||||||
|
|
||||||
import { ScrollableBody } from './ScrollableBody'
|
|
||||||
|
|
||||||
describe('<ScrollableBody />', () => {
|
|
||||||
it('should render successfully', () => {
|
|
||||||
const { baseElement } = render(<ScrollableBody />)
|
|
||||||
expect(baseElement).toBeTruthy()
|
|
||||||
})
|
|
||||||
})
|
|
@ -1 +0,0 @@
|
|||||||
export * from './ScrollableBody'
|
|
@ -1,10 +0,0 @@
|
|||||||
import { render } from '@testing-library/react'
|
|
||||||
|
|
||||||
import { Button } from '.'
|
|
||||||
|
|
||||||
describe('<Button />', () => {
|
|
||||||
it('should render', () => {
|
|
||||||
const { getByText } = render(<Button>Submit</Button>)
|
|
||||||
expect(getByText('Submit')).toBeInTheDocument()
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,5 +1,5 @@
|
|||||||
import { forwardRef } from 'react'
|
import { forwardRef } from 'react'
|
||||||
import classNames from 'classnames'
|
import classNames from 'clsx'
|
||||||
|
|
||||||
const className =
|
const className =
|
||||||
'py-2 px-6 font-paragraph rounded-lg bg-transparent border hover:text-white dark:hover:text-black fill-current stroke-current transform transition-colors duration-300 ease-in-out focus:outline-none focus:text-white dark:focus:text-black'
|
'py-2 px-6 font-paragraph rounded-lg bg-transparent border hover:text-white dark:hover:text-black fill-current stroke-current transform transition-colors duration-300 ease-in-out focus:outline-none focus:text-white dark:focus:text-black'
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
import { render } from '@testing-library/react'
|
|
||||||
|
|
||||||
import { Checkbox } from './Checkbox'
|
|
||||||
|
|
||||||
describe('<Checkbox />', () => {
|
|
||||||
it('should render successfully', () => {
|
|
||||||
const { baseElement } = render(<Checkbox label='Checkbox' />)
|
|
||||||
expect(baseElement).toBeTruthy()
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,4 +1,4 @@
|
|||||||
import classNames from 'classnames'
|
import classNames from 'clsx'
|
||||||
|
|
||||||
export interface CheckboxProps extends React.ComponentPropsWithRef<'input'> {
|
export interface CheckboxProps extends React.ComponentPropsWithRef<'input'> {
|
||||||
className?: string
|
className?: string
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
import { render } from '@testing-library/react'
|
|
||||||
|
|
||||||
import { Divider } from '.'
|
|
||||||
|
|
||||||
describe('<Divider />', () => {
|
|
||||||
it('should render successfully', () => {
|
|
||||||
const { baseElement } = render(<Divider />)
|
|
||||||
expect(baseElement).toBeTruthy()
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,34 +0,0 @@
|
|||||||
import { render } from '@testing-library/react'
|
|
||||||
|
|
||||||
import { FormState } from '.'
|
|
||||||
|
|
||||||
describe('<FormState />', () => {
|
|
||||||
it('should return nothing if the state is idle', () => {
|
|
||||||
const { container } = render(<FormState state='idle' />)
|
|
||||||
expect(container.innerHTML.length).toEqual(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should return nothing if the message is null', () => {
|
|
||||||
const { container } = render(<FormState state='error' />)
|
|
||||||
expect(container.innerHTML.length).toEqual(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should render the <Loader /> if state is loading', () => {
|
|
||||||
const { getByTestId } = render(<FormState state='loading' />)
|
|
||||||
expect(getByTestId('loader')).toBeInTheDocument()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should render the success message if state is success', () => {
|
|
||||||
const message = 'Success Message'
|
|
||||||
const { getByText } = render(
|
|
||||||
<FormState state='success' message={message} />
|
|
||||||
)
|
|
||||||
expect(getByText(message)).toBeInTheDocument()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should render the error message if state is error', () => {
|
|
||||||
const message = 'Error Message'
|
|
||||||
const { getByText } = render(<FormState state='error' message={message} />)
|
|
||||||
expect(getByText(message)).toBeInTheDocument()
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,7 +1,7 @@
|
|||||||
import classNames from 'classnames'
|
import classNames from 'clsx'
|
||||||
import useTranslation from 'next-translate/useTranslation'
|
import useTranslation from 'next-translate/useTranslation'
|
||||||
|
import type { FetchState as FormStateType } from 'react-component-form'
|
||||||
|
|
||||||
import { FetchState as FormStateType } from '../../../hooks/useFetchState'
|
|
||||||
import { Loader } from '../Loader'
|
import { Loader } from '../Loader'
|
||||||
|
|
||||||
export interface FormStateProps extends React.ComponentPropsWithoutRef<'div'> {
|
export interface FormStateProps extends React.ComponentPropsWithoutRef<'div'> {
|
||||||
@ -16,7 +16,7 @@ export const FormState: React.FC<FormStateProps> = (props) => {
|
|||||||
|
|
||||||
if (state === 'loading') {
|
if (state === 'loading') {
|
||||||
return (
|
return (
|
||||||
<div data-testid='loader' className='mt-8 flex justify-center'>
|
<div data-cy='loader' className='mt-8 flex justify-center'>
|
||||||
<Loader />
|
<Loader />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
@ -27,7 +27,6 @@ export const FormState: React.FC<FormStateProps> = (props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
|
||||||
<div
|
<div
|
||||||
{...rest}
|
{...rest}
|
||||||
className={classNames(
|
className={classNames(
|
||||||
@ -39,19 +38,10 @@ export const FormState: React.FC<FormStateProps> = (props) => {
|
|||||||
}
|
}
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className='thumbnail inline bg-cover font-headline' />
|
<div className='inline bg-cover font-headline' />
|
||||||
<span id={id} className='pl-2'>
|
<span id={id} className='pl-2'>
|
||||||
<b>{t(`errors:${state}`)}:</b> {message}
|
<b>{t(`errors:${state}`)}:</b> {message}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style jsx>{`
|
|
||||||
.thumbnail {
|
|
||||||
height: 20px;
|
|
||||||
width: 20px;
|
|
||||||
background-image: url('/images/svg/icons/input/${state}.svg');
|
|
||||||
}
|
|
||||||
`}</style>
|
|
||||||
</>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
import { render } from '@testing-library/react'
|
|
||||||
import { CogIcon } from '@heroicons/react/solid'
|
|
||||||
|
|
||||||
import { IconButton } from './IconButton'
|
|
||||||
|
|
||||||
describe('<IconButton />', () => {
|
|
||||||
it('should render successfully', () => {
|
|
||||||
const { baseElement } = render(
|
|
||||||
<IconButton className='h-10 w-10'>
|
|
||||||
<CogIcon />
|
|
||||||
</IconButton>
|
|
||||||
)
|
|
||||||
expect(baseElement).toBeTruthy()
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,4 +1,4 @@
|
|||||||
import classNames from 'classnames'
|
import classNames from 'clsx'
|
||||||
|
|
||||||
export interface IconButtonProps
|
export interface IconButtonProps
|
||||||
extends React.ComponentPropsWithoutRef<'button'> {}
|
extends React.ComponentPropsWithoutRef<'button'> {}
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
import { render } from '@testing-library/react'
|
|
||||||
|
|
||||||
import { IconLink } from './IconLink'
|
|
||||||
|
|
||||||
describe('<IconLink />', () => {
|
|
||||||
it('should render successfully', () => {
|
|
||||||
const { baseElement } = render(<IconLink href='' />)
|
|
||||||
expect(baseElement).toBeTruthy()
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,5 +1,5 @@
|
|||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import classNames from 'classnames'
|
import classNames from 'clsx'
|
||||||
|
|
||||||
export interface IconLinkProps {
|
export interface IconLinkProps {
|
||||||
selected?: boolean
|
selected?: boolean
|
||||||
@ -8,7 +8,9 @@ export interface IconLinkProps {
|
|||||||
className?: string
|
className?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const IconLink: React.FC<IconLinkProps> = (props) => {
|
export const IconLink: React.FC<React.PropsWithChildren<IconLinkProps>> = (
|
||||||
|
props
|
||||||
|
) => {
|
||||||
const { children, selected, href, title, className } = props
|
const { children, selected, href, title, className } = props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
import { render, fireEvent } from '@testing-library/react'
|
|
||||||
|
|
||||||
import { Input, getInputType } from '.'
|
|
||||||
|
|
||||||
describe('<Input />', () => {
|
|
||||||
it('should render the label', () => {
|
|
||||||
const labelContent = 'label content'
|
|
||||||
const { getByText } = render(<Input label={labelContent} />)
|
|
||||||
expect(getByText(labelContent)).toBeInTheDocument()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should not render forgot password link', () => {
|
|
||||||
const { queryByTestId } = render(
|
|
||||||
<Input type='text' label='content' showForgotPassword />
|
|
||||||
)
|
|
||||||
const forgotPasswordLink = queryByTestId('forgot-password-link')
|
|
||||||
expect(forgotPasswordLink).not.toBeInTheDocument()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should render forgot password link', () => {
|
|
||||||
const { queryByTestId } = render(
|
|
||||||
<Input type='password' label='content' showForgotPassword />
|
|
||||||
)
|
|
||||||
const forgotPasswordLink = queryByTestId('forgot-password-link')
|
|
||||||
expect(forgotPasswordLink).toBeInTheDocument()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should not render the eye icon if the input is not of type "password"', () => {
|
|
||||||
const { queryByTestId } = render(<Input type='text' label='content' />)
|
|
||||||
const passwordEye = queryByTestId('password-eye')
|
|
||||||
expect(passwordEye).not.toBeInTheDocument()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should handlePassword with eye icon', async () => {
|
|
||||||
const { findByTestId } = render(<Input type='password' label='content' />)
|
|
||||||
const passwordEye = await findByTestId('password-eye')
|
|
||||||
const input = await findByTestId('input')
|
|
||||||
expect(input).toHaveAttribute('type', 'password')
|
|
||||||
fireEvent.click(passwordEye)
|
|
||||||
expect(input).toHaveAttribute('type', 'text')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('getInputType', () => {
|
|
||||||
it('should return `text`', () => {
|
|
||||||
expect(getInputType('password')).toEqual('text')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should return `password`', () => {
|
|
||||||
expect(getInputType('text')).toEqual('password')
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,7 +1,7 @@
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import useTranslation from 'next-translate/useTranslation'
|
import useTranslation from 'next-translate/useTranslation'
|
||||||
import classNames from 'classnames'
|
import classNames from 'clsx'
|
||||||
|
|
||||||
import { FormState } from '../FormState'
|
import { FormState } from '../FormState'
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ export const Input: React.FC<InputProps> = (props) => {
|
|||||||
<Link href='/authentication/forgot-password'>
|
<Link href='/authentication/forgot-password'>
|
||||||
<a
|
<a
|
||||||
className='text-center font-headline text-xs text-green-800 hover:underline dark:text-green-400 sm:text-sm'
|
className='text-center font-headline text-xs text-green-800 hover:underline dark:text-green-400 sm:text-sm'
|
||||||
data-testid='forgot-password-link'
|
data-cy='forgot-password-link'
|
||||||
>
|
>
|
||||||
{t('authentication:forgot-password')}
|
{t('authentication:forgot-password')}
|
||||||
</a>
|
</a>
|
||||||
@ -56,7 +56,6 @@ export const Input: React.FC<InputProps> = (props) => {
|
|||||||
</div>
|
</div>
|
||||||
<div className='relative mt-0'>
|
<div className='relative mt-0'>
|
||||||
<input
|
<input
|
||||||
data-testid='input'
|
|
||||||
data-cy={`input-${name ?? 'name'}`}
|
data-cy={`input-${name ?? 'name'}`}
|
||||||
className='h-11 w-full rounded-lg border border-transparent bg-[#f1f1f1] px-3 font-paragraph leading-10 text-[#2a2a2a] caret-green-600 focus:border focus:shadow-green focus:outline-none'
|
className='h-11 w-full rounded-lg border border-transparent bg-[#f1f1f1] px-3 font-paragraph leading-10 text-[#2a2a2a] caret-green-600 focus:border focus:shadow-green focus:outline-none'
|
||||||
{...rest}
|
{...rest}
|
||||||
@ -66,7 +65,7 @@ export const Input: React.FC<InputProps> = (props) => {
|
|||||||
/>
|
/>
|
||||||
{type === 'password' && (
|
{type === 'password' && (
|
||||||
<div
|
<div
|
||||||
data-testid='password-eye'
|
data-cy='password-eye'
|
||||||
onClick={handlePassword}
|
onClick={handlePassword}
|
||||||
className='password-eye absolute cursor-pointer bg-[#f1f1f1] bg-cover'
|
className='password-eye absolute cursor-pointer bg-[#f1f1f1] bg-cover'
|
||||||
/>
|
/>
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
import { render } from '@testing-library/react'
|
|
||||||
|
|
||||||
import { Loader } from '.'
|
|
||||||
|
|
||||||
describe('<Loader />', () => {
|
|
||||||
it('should render with correct width and height', async () => {
|
|
||||||
const size = 20
|
|
||||||
const { findByTestId } = render(<Loader width={size} height={size} />)
|
|
||||||
const progressSpinner = await findByTestId('progress-spinner')
|
|
||||||
expect(progressSpinner).toHaveStyle(`width: ${size}px`)
|
|
||||||
expect(progressSpinner).toHaveStyle(`height: ${size}px`)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should render with default width and height', async () => {
|
|
||||||
const { findByTestId } = render(<Loader />)
|
|
||||||
const progressSpinner = await findByTestId('progress-spinner')
|
|
||||||
expect(progressSpinner).toHaveStyle('width: 50px')
|
|
||||||
expect(progressSpinner).toHaveStyle('height: 50px')
|
|
||||||
})
|
|
||||||
})
|
|
@ -9,7 +9,7 @@ export const Loader: React.FC<LoaderProps> = (props) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={props.className}>
|
<div className={props.className}>
|
||||||
<div data-testid='progress-spinner' className='progress-spinner'>
|
<div data-cy='progress-spinner' className='progress-spinner'>
|
||||||
<svg className='progress-spinner-svg' viewBox='25 25 50 50'>
|
<svg className='progress-spinner-svg' viewBox='25 25 50 50'>
|
||||||
<circle
|
<circle
|
||||||
className='progress-spinner-circle'
|
className='progress-spinner-circle'
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
import { render } from '@testing-library/react'
|
|
||||||
|
|
||||||
import { Main } from '.'
|
|
||||||
|
|
||||||
describe('<Main />', () => {
|
|
||||||
it('should render successfully', () => {
|
|
||||||
const { baseElement } = render(<Main />)
|
|
||||||
expect(baseElement).toBeTruthy()
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,10 +1,10 @@
|
|||||||
import classNames from 'classnames'
|
import classNames from 'clsx'
|
||||||
|
|
||||||
export interface MainProps {
|
export interface MainProps {
|
||||||
className?: string
|
className?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Main: React.FC<MainProps> = (props) => {
|
export const Main: React.FC<React.PropsWithChildren<MainProps>> = (props) => {
|
||||||
const { children, className } = props
|
const { children, className } = props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
import { render } from '@testing-library/react'
|
|
||||||
|
|
||||||
import { SocialMedia, SocialMediaButton } from '.'
|
|
||||||
|
|
||||||
describe('<SocialMediaButton />', () => {
|
|
||||||
it('should render the social media', async () => {
|
|
||||||
const socialMedia: SocialMedia = 'Discord'
|
|
||||||
const { findByAltText } = render(
|
|
||||||
<SocialMediaButton socialMedia={socialMedia} />
|
|
||||||
)
|
|
||||||
const socialMediaButton = await findByAltText(socialMedia)
|
|
||||||
expect(socialMediaButton).toBeInTheDocument()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should render with a black text color with Google social media', async () => {
|
|
||||||
const socialMedia: SocialMedia = 'Google'
|
|
||||||
const { findByTestId } = render(
|
|
||||||
<SocialMediaButton socialMedia={socialMedia} />
|
|
||||||
)
|
|
||||||
const button = await findByTestId('social-media-button')
|
|
||||||
expect(button).toHaveStyle('color: #000')
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,6 +1,6 @@
|
|||||||
import { useMemo } from 'react'
|
import { useMemo } from 'react'
|
||||||
import Image from 'next/image'
|
import Image from 'next/image'
|
||||||
import classNames from 'classnames'
|
import classNames from 'clsx'
|
||||||
|
|
||||||
import { ProviderOAuth } from '../../../models/OAuth'
|
import { ProviderOAuth } from '../../../models/OAuth'
|
||||||
|
|
||||||
@ -54,7 +54,6 @@ export const SocialMediaButton: React.FC<SocialMediaButtonProps> = (props) => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<button
|
<button
|
||||||
data-testid='social-media-button'
|
|
||||||
{...rest}
|
{...rest}
|
||||||
className={classNames(className, 'button', givenClassName)}
|
className={classNames(className, 'button', givenClassName)}
|
||||||
>
|
>
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
import { render } from '@testing-library/react'
|
|
||||||
|
|
||||||
import { Textarea } from './Textarea'
|
|
||||||
|
|
||||||
describe('<Textarea />', () => {
|
|
||||||
it('should render successfully', () => {
|
|
||||||
const { baseElement } = render(<Textarea label='Textarea' />)
|
|
||||||
expect(baseElement).toBeTruthy()
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,4 +1,4 @@
|
|||||||
import { createContext, useContext, useEffect } from 'react'
|
import { createContext, useContext, useEffect, useMemo } from 'react'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
|
|
||||||
import { NextPage, usePagination } from '../hooks/usePagination'
|
import { NextPage, usePagination } from '../hooks/usePagination'
|
||||||
@ -6,6 +6,7 @@ import { useAuthentication } from '../tools/authentication'
|
|||||||
import { Channel, ChannelWithDefaultChannelId } from '../models/Channel'
|
import { Channel, ChannelWithDefaultChannelId } from '../models/Channel'
|
||||||
import { GuildsChannelsPath } from '../components/Application'
|
import { GuildsChannelsPath } from '../components/Application'
|
||||||
import { handleSocketData, SocketData } from '../tools/handleSocketData'
|
import { handleSocketData, SocketData } from '../tools/handleSocketData'
|
||||||
|
import { CacheKey, CHANNELS_CACHE_KEY } from '../tools/cache'
|
||||||
|
|
||||||
export interface Channels {
|
export interface Channels {
|
||||||
channels: Channel[]
|
channels: Channel[]
|
||||||
@ -20,11 +21,17 @@ export interface ChannelsProviderProps {
|
|||||||
path: GuildsChannelsPath
|
path: GuildsChannelsPath
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ChannelsProvider: React.FC<ChannelsProviderProps> = (props) => {
|
export const ChannelsProvider: React.FC<
|
||||||
|
React.PropsWithChildren<ChannelsProviderProps>
|
||||||
|
> = (props) => {
|
||||||
const { path, children } = props
|
const { path, children } = props
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { authentication } = useAuthentication()
|
const { authentication } = useAuthentication()
|
||||||
|
|
||||||
|
const cacheKey = useMemo<CacheKey>(() => {
|
||||||
|
return `${path.guildId}-${CHANNELS_CACHE_KEY}`
|
||||||
|
}, [path.guildId])
|
||||||
|
|
||||||
const {
|
const {
|
||||||
items: channels,
|
items: channels,
|
||||||
hasMore,
|
hasMore,
|
||||||
@ -33,14 +40,15 @@ export const ChannelsProvider: React.FC<ChannelsProviderProps> = (props) => {
|
|||||||
setItems
|
setItems
|
||||||
} = usePagination<Channel>({
|
} = usePagination<Channel>({
|
||||||
api: authentication.api,
|
api: authentication.api,
|
||||||
url: `/guilds/${path.guildId}/channels`
|
url: `/guilds/${path.guildId}/channels`,
|
||||||
|
cacheKey
|
||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
authentication.socket.on(
|
authentication?.socket?.on(
|
||||||
'channels',
|
'channels',
|
||||||
async (data: SocketData<ChannelWithDefaultChannelId>) => {
|
async (data: SocketData<ChannelWithDefaultChannelId>) => {
|
||||||
handleSocketData({ data, setItems })
|
handleSocketData({ data, setItems, cacheKey })
|
||||||
if (data.action === 'delete') {
|
if (data.action === 'delete') {
|
||||||
await router.push(
|
await router.push(
|
||||||
`/application/${path.guildId}/${data.item.defaultChannelId}`
|
`/application/${path.guildId}/${data.item.defaultChannelId}`
|
||||||
@ -50,9 +58,9 @@ export const ChannelsProvider: React.FC<ChannelsProviderProps> = (props) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
authentication.socket.off('channels')
|
authentication?.socket?.off('channels')
|
||||||
}
|
}
|
||||||
}, [authentication.socket, path.guildId, router, setItems])
|
}, [authentication.socket, path.guildId, router, setItems, cacheKey])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
resetPagination()
|
resetPagination()
|
||||||
@ -69,7 +77,7 @@ export const ChannelsProvider: React.FC<ChannelsProviderProps> = (props) => {
|
|||||||
export const useChannels = (): Channels => {
|
export const useChannels = (): Channels => {
|
||||||
const channels = useContext(ChannelsContext)
|
const channels = useContext(ChannelsContext)
|
||||||
if (channels === defaultChannelsContext) {
|
if (channels === defaultChannelsContext) {
|
||||||
throw new Error('useChannels must be used within ChannelsProvider')
|
throw new Error('`useChannels` must be used within `ChannelsProvider`')
|
||||||
}
|
}
|
||||||
return channels
|
return channels
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,7 @@ export interface GuildMember {
|
|||||||
member: Member
|
member: Member
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GuildMemberResult extends GuildMember {
|
export interface GuildMemberResult extends GuildMember {}
|
||||||
setGuildMember: React.Dispatch<React.SetStateAction<GuildMember>>
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface GuildMemberProps {
|
export interface GuildMemberProps {
|
||||||
guildMember: GuildMember
|
guildMember: GuildMember
|
||||||
@ -27,7 +25,9 @@ const GuildMemberContext = createContext<GuildMemberResult>(
|
|||||||
defaultGuildMemberContext
|
defaultGuildMemberContext
|
||||||
)
|
)
|
||||||
|
|
||||||
export const GuildMemberProvider: React.FC<GuildMemberProps> = (props) => {
|
export const GuildMemberProvider: React.FC<
|
||||||
|
React.PropsWithChildren<GuildMemberProps>
|
||||||
|
> = (props) => {
|
||||||
const { path, children } = props
|
const { path, children } = props
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const [guildMember, setGuildMember] = useState(props.guildMember)
|
const [guildMember, setGuildMember] = useState(props.guildMember)
|
||||||
@ -45,7 +45,7 @@ export const GuildMemberProvider: React.FC<GuildMemberProps> = (props) => {
|
|||||||
}, [path, authentication.api])
|
}, [path, authentication.api])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
authentication.socket.on(
|
authentication?.socket?.on(
|
||||||
'guilds',
|
'guilds',
|
||||||
async (data: SocketData<GuildWithDefaultChannelId>) => {
|
async (data: SocketData<GuildWithDefaultChannelId>) => {
|
||||||
if (data.item.id === path.guildId) {
|
if (data.item.id === path.guildId) {
|
||||||
@ -70,15 +70,14 @@ export const GuildMemberProvider: React.FC<GuildMemberProps> = (props) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
authentication.socket.off('guilds')
|
authentication?.socket?.off('guilds')
|
||||||
}
|
}
|
||||||
}, [authentication.socket, path.guildId, router])
|
}, [authentication.socket, path.guildId, router])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<GuildMemberContext.Provider
|
<GuildMemberContext.Provider
|
||||||
value={{
|
value={{
|
||||||
...guildMember,
|
...guildMember
|
||||||
setGuildMember
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
@ -89,7 +88,9 @@ export const GuildMemberProvider: React.FC<GuildMemberProps> = (props) => {
|
|||||||
export const useGuildMember = (): GuildMemberResult => {
|
export const useGuildMember = (): GuildMemberResult => {
|
||||||
const guildMember = useContext(GuildMemberContext)
|
const guildMember = useContext(GuildMemberContext)
|
||||||
if (guildMember === defaultGuildMemberContext) {
|
if (guildMember === defaultGuildMemberContext) {
|
||||||
throw new Error('useGuildMember must be used within GuildMemberProvider')
|
throw new Error(
|
||||||
|
'`useGuildMember` must be used within `GuildMemberProvider`'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return guildMember
|
return guildMember
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import { NextPage, usePagination } from '../hooks/usePagination'
|
|||||||
import { useAuthentication } from '../tools/authentication'
|
import { useAuthentication } from '../tools/authentication'
|
||||||
import { GuildWithDefaultChannelId } from '../models/Guild'
|
import { GuildWithDefaultChannelId } from '../models/Guild'
|
||||||
import { handleSocketData, SocketData } from '../tools/handleSocketData'
|
import { handleSocketData, SocketData } from '../tools/handleSocketData'
|
||||||
|
import { GUILDS_CACHE_KEY } from '../tools/cache'
|
||||||
|
|
||||||
export interface Guilds {
|
export interface Guilds {
|
||||||
guilds: GuildWithDefaultChannelId[]
|
guilds: GuildWithDefaultChannelId[]
|
||||||
@ -14,7 +15,9 @@ export interface Guilds {
|
|||||||
const defaultGuildsContext = {} as any
|
const defaultGuildsContext = {} as any
|
||||||
const GuildsContext = createContext<Guilds>(defaultGuildsContext)
|
const GuildsContext = createContext<Guilds>(defaultGuildsContext)
|
||||||
|
|
||||||
export const GuildsProvider: React.FC = (props) => {
|
export const GuildsProvider: React.FC<React.PropsWithChildren<{}>> = (
|
||||||
|
props
|
||||||
|
) => {
|
||||||
const { children } = props
|
const { children } = props
|
||||||
|
|
||||||
const { authentication } = useAuthentication()
|
const { authentication } = useAuthentication()
|
||||||
@ -27,19 +30,20 @@ export const GuildsProvider: React.FC = (props) => {
|
|||||||
setItems
|
setItems
|
||||||
} = usePagination<GuildWithDefaultChannelId>({
|
} = usePagination<GuildWithDefaultChannelId>({
|
||||||
api: authentication.api,
|
api: authentication.api,
|
||||||
url: '/guilds'
|
url: '/guilds',
|
||||||
|
cacheKey: GUILDS_CACHE_KEY
|
||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
authentication.socket.on(
|
authentication?.socket?.on(
|
||||||
'guilds',
|
'guilds',
|
||||||
(data: SocketData<GuildWithDefaultChannelId>) => {
|
(data: SocketData<GuildWithDefaultChannelId>) => {
|
||||||
handleSocketData({ data, setItems })
|
handleSocketData({ data, setItems, cacheKey: GUILDS_CACHE_KEY })
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
authentication.socket.off('guilds')
|
authentication?.socket?.off('guilds')
|
||||||
}
|
}
|
||||||
}, [authentication.socket, setItems])
|
}, [authentication.socket, setItems])
|
||||||
|
|
||||||
@ -58,7 +62,7 @@ export const GuildsProvider: React.FC = (props) => {
|
|||||||
export const useGuilds = (): Guilds => {
|
export const useGuilds = (): Guilds => {
|
||||||
const guilds = useContext(GuildsContext)
|
const guilds = useContext(GuildsContext)
|
||||||
if (guilds === defaultGuildsContext) {
|
if (guilds === defaultGuildsContext) {
|
||||||
throw new Error('useGuilds must be used within GuildsProvider')
|
throw new Error('`useGuilds` must be used within `GuildsProvider`')
|
||||||
}
|
}
|
||||||
return guilds
|
return guilds
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { createContext, useContext, useEffect } from 'react'
|
import { createContext, useContext, useEffect, useMemo } from 'react'
|
||||||
|
|
||||||
import { NextPage, usePagination } from '../hooks/usePagination'
|
import { NextPage, usePagination } from '../hooks/usePagination'
|
||||||
import { useAuthentication } from '../tools/authentication'
|
import { useAuthentication } from '../tools/authentication'
|
||||||
@ -6,6 +6,7 @@ import { MemberWithPublicUser } from '../models/Member'
|
|||||||
import { GuildsChannelsPath } from '../components/Application'
|
import { GuildsChannelsPath } from '../components/Application'
|
||||||
import { handleSocketData, SocketData } from '../tools/handleSocketData'
|
import { handleSocketData, SocketData } from '../tools/handleSocketData'
|
||||||
import { User } from '../models/User'
|
import { User } from '../models/User'
|
||||||
|
import { CacheKey, MEMBERS_CACHE_KEY } from '../tools/cache'
|
||||||
|
|
||||||
export interface Members {
|
export interface Members {
|
||||||
members: MemberWithPublicUser[]
|
members: MemberWithPublicUser[]
|
||||||
@ -20,11 +21,17 @@ export interface MembersProviderProps {
|
|||||||
path: GuildsChannelsPath
|
path: GuildsChannelsPath
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MembersProviders: React.FC<MembersProviderProps> = (props) => {
|
export const MembersProviders: React.FC<
|
||||||
|
React.PropsWithChildren<MembersProviderProps>
|
||||||
|
> = (props) => {
|
||||||
const { children, path } = props
|
const { children, path } = props
|
||||||
|
|
||||||
const { authentication } = useAuthentication()
|
const { authentication } = useAuthentication()
|
||||||
|
|
||||||
|
const cacheKey = useMemo<CacheKey>(() => {
|
||||||
|
return `${path.guildId}-${MEMBERS_CACHE_KEY}`
|
||||||
|
}, [path.guildId])
|
||||||
|
|
||||||
const {
|
const {
|
||||||
items: members,
|
items: members,
|
||||||
hasMore,
|
hasMore,
|
||||||
@ -33,18 +40,19 @@ export const MembersProviders: React.FC<MembersProviderProps> = (props) => {
|
|||||||
setItems
|
setItems
|
||||||
} = usePagination<MemberWithPublicUser>({
|
} = usePagination<MemberWithPublicUser>({
|
||||||
api: authentication.api,
|
api: authentication.api,
|
||||||
url: `/guilds/${path.guildId}/members`
|
url: `/guilds/${path.guildId}/members`,
|
||||||
|
cacheKey
|
||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
authentication.socket.on(
|
authentication?.socket?.on(
|
||||||
'members',
|
'members',
|
||||||
(data: SocketData<MemberWithPublicUser>) => {
|
(data: SocketData<MemberWithPublicUser>) => {
|
||||||
handleSocketData({ data, setItems })
|
handleSocketData({ data, setItems, cacheKey })
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
authentication.socket.on('users', (data: SocketData<User>) => {
|
authentication?.socket?.on('users', (data: SocketData<User>) => {
|
||||||
setItems((oldItems) => {
|
setItems((oldItems) => {
|
||||||
const newItems = [...oldItems]
|
const newItems = [...oldItems]
|
||||||
switch (data.action) {
|
switch (data.action) {
|
||||||
@ -63,10 +71,10 @@ export const MembersProviders: React.FC<MembersProviderProps> = (props) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
authentication.socket.off('members')
|
authentication?.socket?.off('members')
|
||||||
authentication.socket.off('users')
|
authentication?.socket?.off('users')
|
||||||
}
|
}
|
||||||
}, [authentication.socket, setItems])
|
}, [authentication.socket, setItems, cacheKey])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
resetPagination()
|
resetPagination()
|
||||||
@ -83,7 +91,7 @@ export const MembersProviders: React.FC<MembersProviderProps> = (props) => {
|
|||||||
export const useMembers = (): Members => {
|
export const useMembers = (): Members => {
|
||||||
const members = useContext(MembersContext)
|
const members = useContext(MembersContext)
|
||||||
if (members === defaultMembersContext) {
|
if (members === defaultMembersContext) {
|
||||||
throw new Error('useMembers must be used within MembersProvider')
|
throw new Error('`useMembers` must be used within `MembersProvider`')
|
||||||
}
|
}
|
||||||
return members
|
return members
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import { createContext, useContext, useEffect } from 'react'
|
import { createContext, useContext, useEffect, useMemo } from 'react'
|
||||||
|
|
||||||
import { NextPage, usePagination } from '../hooks/usePagination'
|
import { NextPage, usePagination } from '../hooks/usePagination'
|
||||||
import { useAuthentication } from '../tools/authentication'
|
import { useAuthentication } from '../tools/authentication'
|
||||||
import { MessageWithMember } from '../models/Message'
|
import { MessageWithMember } from '../models/Message'
|
||||||
import { GuildsChannelsPath } from '../components/Application'
|
import { GuildsChannelsPath } from '../components/Application'
|
||||||
import { handleSocketData, SocketData } from '../tools/handleSocketData'
|
import { handleSocketData, SocketData } from '../tools/handleSocketData'
|
||||||
|
import { CacheKey, MESSAGES_CACHE_KEY } from '../tools/cache'
|
||||||
|
|
||||||
export interface Messages {
|
export interface Messages {
|
||||||
messages: MessageWithMember[]
|
messages: MessageWithMember[]
|
||||||
@ -19,9 +20,15 @@ export interface MessagesProviderProps {
|
|||||||
path: GuildsChannelsPath
|
path: GuildsChannelsPath
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MessagesProvider: React.FC<MessagesProviderProps> = (props) => {
|
export const MessagesProvider: React.FC<
|
||||||
|
React.PropsWithChildren<MessagesProviderProps>
|
||||||
|
> = (props) => {
|
||||||
const { path, children } = props
|
const { path, children } = props
|
||||||
const { authentication } = useAuthentication()
|
const { authentication, user } = useAuthentication()
|
||||||
|
|
||||||
|
const cacheKey = useMemo<CacheKey>(() => {
|
||||||
|
return `${path.channelId}-${MESSAGES_CACHE_KEY}`
|
||||||
|
}, [path.channelId])
|
||||||
|
|
||||||
const {
|
const {
|
||||||
items: messages,
|
items: messages,
|
||||||
@ -32,11 +39,12 @@ export const MessagesProvider: React.FC<MessagesProviderProps> = (props) => {
|
|||||||
} = usePagination<MessageWithMember>({
|
} = usePagination<MessageWithMember>({
|
||||||
api: authentication.api,
|
api: authentication.api,
|
||||||
url: `/channels/${path.channelId}/messages`,
|
url: `/channels/${path.channelId}/messages`,
|
||||||
inverse: true
|
inverse: true,
|
||||||
|
cacheKey
|
||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
authentication.socket.on(
|
authentication?.socket?.on(
|
||||||
'messages',
|
'messages',
|
||||||
(data: SocketData<MessageWithMember>) => {
|
(data: SocketData<MessageWithMember>) => {
|
||||||
if (data.item.channelId === path.channelId) {
|
if (data.item.channelId === path.channelId) {
|
||||||
@ -46,8 +54,11 @@ export const MessagesProvider: React.FC<MessagesProviderProps> = (props) => {
|
|||||||
const isAtBottom =
|
const isAtBottom =
|
||||||
messagesDiv.scrollHeight - messagesDiv.scrollTop <=
|
messagesDiv.scrollHeight - messagesDiv.scrollTop <=
|
||||||
messagesDiv.clientHeight
|
messagesDiv.clientHeight
|
||||||
handleSocketData({ data, setItems })
|
handleSocketData({ data, setItems, cacheKey })
|
||||||
if (data.action === 'create' && isAtBottom) {
|
if (
|
||||||
|
data.action === 'create' &&
|
||||||
|
(isAtBottom || data.item.member.userId === user.id)
|
||||||
|
) {
|
||||||
messagesDiv.scrollTo(0, messagesDiv.scrollHeight)
|
messagesDiv.scrollTo(0, messagesDiv.scrollHeight)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -55,9 +66,9 @@ export const MessagesProvider: React.FC<MessagesProviderProps> = (props) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
authentication.socket.off('messages')
|
authentication?.socket?.off('messages')
|
||||||
}
|
}
|
||||||
}, [authentication.socket, setItems, path])
|
}, [authentication.socket, setItems, path, user.id, cacheKey])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
resetPagination()
|
resetPagination()
|
||||||
@ -79,7 +90,7 @@ export const MessagesProvider: React.FC<MessagesProviderProps> = (props) => {
|
|||||||
export const useMessages = (): Messages => {
|
export const useMessages = (): Messages => {
|
||||||
const messages = useContext(MessagesContext)
|
const messages = useContext(MessagesContext)
|
||||||
if (messages === defaultMessagesContext) {
|
if (messages === defaultMessagesContext) {
|
||||||
throw new Error('useMessages must be used within a MessagesProvider')
|
throw new Error('`useMessages` must be used within a `MessagesProvider`')
|
||||||
}
|
}
|
||||||
return messages
|
return messages
|
||||||
}
|
}
|
||||||
|
72
cypress.config.ts
Normal file
72
cypress.config.ts
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import path from 'node:path'
|
||||||
|
|
||||||
|
import { defineConfig } from 'cypress'
|
||||||
|
import { getLocal } from 'mockttp'
|
||||||
|
import type { Mockttp } from 'mockttp'
|
||||||
|
|
||||||
|
import { API_DEFAULT_PORT } from './tools/api'
|
||||||
|
import { Handlers, Method } from './cypress/fixtures/handler'
|
||||||
|
|
||||||
|
const UPLOADS_FIXTURES_DIRECTORY = path.join(
|
||||||
|
process.cwd(),
|
||||||
|
'cypress',
|
||||||
|
'fixtures',
|
||||||
|
'uploads'
|
||||||
|
)
|
||||||
|
|
||||||
|
let server: Mockttp | null = null
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
fixturesFolder: false,
|
||||||
|
video: false,
|
||||||
|
downloadsFolder: undefined,
|
||||||
|
screenshotOnRunFailure: false,
|
||||||
|
|
||||||
|
e2e: {
|
||||||
|
baseUrl: 'http://localhost:3000',
|
||||||
|
supportFile: false,
|
||||||
|
setupNodeEvents(on, config) {
|
||||||
|
on('task', {
|
||||||
|
async startMockServer(handlers: Handlers): Promise<null> {
|
||||||
|
server = getLocal({
|
||||||
|
cors: true
|
||||||
|
})
|
||||||
|
await server.start(API_DEFAULT_PORT)
|
||||||
|
for (const handler of handlers) {
|
||||||
|
const { isFile = false } = handler.response
|
||||||
|
const method = handler.method.toLowerCase() as Lowercase<Method>
|
||||||
|
if (isFile) {
|
||||||
|
await server[method](handler.url).thenFromFile(
|
||||||
|
handler.response.statusCode,
|
||||||
|
path.join(UPLOADS_FIXTURES_DIRECTORY, ...handler.response.body)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
await server[method](handler.url).thenJson(
|
||||||
|
handler.response.statusCode,
|
||||||
|
handler.response.body
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
},
|
||||||
|
|
||||||
|
async stopMockServer(): Promise<null> {
|
||||||
|
if (server != null) {
|
||||||
|
await server.stop()
|
||||||
|
server = null
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
component: {
|
||||||
|
devServer: {
|
||||||
|
framework: 'next',
|
||||||
|
bundler: 'webpack'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"baseUrl": "http://localhost:3000",
|
|
||||||
"supportFile": false,
|
|
||||||
"video": false,
|
|
||||||
"screenshotOnRunFailure": false
|
|
||||||
}
|
|
@ -0,0 +1,18 @@
|
|||||||
|
import { isStringWithOnlyOneEmoji } from '../../../../components/Emoji/isStringWithOnlyOneEmoji'
|
||||||
|
|
||||||
|
describe('components/Emoji/isStringWithOnlyOneEmoji', () => {
|
||||||
|
it('returns true with a string with only one emoji', () => {
|
||||||
|
expect(isStringWithOnlyOneEmoji(':wave:')).equal(true)
|
||||||
|
expect(isStringWithOnlyOneEmoji(':smile:')).equal(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns false with a string with multiple emoji or with text', () => {
|
||||||
|
expect(isStringWithOnlyOneEmoji(':wave: :smile:')).equal(false)
|
||||||
|
expect(isStringWithOnlyOneEmoji(':wave: some text')).equal(false)
|
||||||
|
expect(isStringWithOnlyOneEmoji('some text :wave:')).equal(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns false with a string without emoji', () => {
|
||||||
|
expect(isStringWithOnlyOneEmoji('some text')).equal(false)
|
||||||
|
})
|
||||||
|
})
|
16
cypress/component/components/Footer.cy.tsx
Normal file
16
cypress/component/components/Footer.cy.tsx
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { Footer } from '../../../components/Footer'
|
||||||
|
|
||||||
|
describe('<Footer />', () => {
|
||||||
|
it('should render with appropriate link tag version', () => {
|
||||||
|
const version = '1.0.0'
|
||||||
|
cy.mount(<Footer version={version} />)
|
||||||
|
cy.contains('Thream')
|
||||||
|
.get('[data-cy=version-link-website]')
|
||||||
|
.should('have.text', `website v${version}`)
|
||||||
|
.should(
|
||||||
|
'have.attr',
|
||||||
|
'href',
|
||||||
|
`https://github.com/Thream/website/releases/tag/v${version}`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
35
cypress/component/components/design/FormState.cy.tsx
Normal file
35
cypress/component/components/design/FormState.cy.tsx
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { FormState } from '../../../../components/design/FormState'
|
||||||
|
|
||||||
|
describe('<FormState />', () => {
|
||||||
|
it('should return nothing if the state is idle', () => {
|
||||||
|
cy.mount(<FormState state='idle' />)
|
||||||
|
.get('[data-cy-root]')
|
||||||
|
.should('be.empty')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should return nothing if the message is null', () => {
|
||||||
|
cy.mount(<FormState state='error' />)
|
||||||
|
.get('[data-cy-root]')
|
||||||
|
.should('be.empty')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should render the <Loader /> if state is loading', () => {
|
||||||
|
cy.mount(<FormState state='loading' />)
|
||||||
|
.get('[data-cy=loader]')
|
||||||
|
.should('be.visible')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should render the success message if state is success', () => {
|
||||||
|
const message = 'Success Message'
|
||||||
|
cy.mount(<FormState state='success' message={message} id='success' />)
|
||||||
|
.get('#success')
|
||||||
|
.contains(message)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should render the error message if state is error', () => {
|
||||||
|
const message = 'Error Message'
|
||||||
|
cy.mount(<FormState state='error' message={message} id='error' />)
|
||||||
|
.get('#error')
|
||||||
|
.contains(message)
|
||||||
|
})
|
||||||
|
})
|
48
cypress/component/components/design/Input.cy.tsx
Normal file
48
cypress/component/components/design/Input.cy.tsx
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import { Input, getInputType } from '../../../../components/design/Input'
|
||||||
|
|
||||||
|
describe('<Input />', () => {
|
||||||
|
it('should render the label', () => {
|
||||||
|
const labelContent = 'label content'
|
||||||
|
cy.mount(<Input label={labelContent} />)
|
||||||
|
.get('label')
|
||||||
|
.should('have.text', labelContent)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should not render forgot password link', () => {
|
||||||
|
cy.mount(<Input type='text' label='content' showForgotPassword />)
|
||||||
|
.get('[data-cy=forgot-password-link]')
|
||||||
|
.should('not.exist')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should render forgot password link', () => {
|
||||||
|
cy.mount(<Input type='password' label='content' showForgotPassword />)
|
||||||
|
.get('[data-cy=forgot-password-link]')
|
||||||
|
.should('exist')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should not render the eye icon if the input is not of type "password"', () => {
|
||||||
|
cy.mount(<Input type='text' label='content' />)
|
||||||
|
.get('[data-cy=password-eye]')
|
||||||
|
.should('not.exist')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should handlePassword with eye icon', async () => {
|
||||||
|
cy.mount(<Input type='password' label='content' />)
|
||||||
|
.get('input')
|
||||||
|
.should('have.attr', 'type', 'password')
|
||||||
|
.get('[data-cy=password-eye]')
|
||||||
|
.click()
|
||||||
|
.get('input')
|
||||||
|
.should('have.attr', 'type', 'text')
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('getInputType', () => {
|
||||||
|
it('should return `text`', () => {
|
||||||
|
expect(getInputType('password')).equal('text')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should return `password`', () => {
|
||||||
|
expect(getInputType('text')).equal('password')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
10
cypress/component/tools/utils/capitalize.cy.ts
Normal file
10
cypress/component/tools/utils/capitalize.cy.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { capitalize } from '../../../../tools/utils/capitalize'
|
||||||
|
|
||||||
|
describe('tools/utils/capitalize', () => {
|
||||||
|
it('should capitalize the first letter of a string', () => {
|
||||||
|
expect(capitalize('hello')).equal('Hello')
|
||||||
|
expect(capitalize('HeLlo')).equal('HeLlo')
|
||||||
|
expect(capitalize('member(s)')).equal('Member(s)')
|
||||||
|
expect(capitalize('Member(s)')).equal('Member(s)')
|
||||||
|
})
|
||||||
|
})
|
@ -49,3 +49,5 @@ describe('Common > Header', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export {}
|
@ -45,3 +45,5 @@ describe('Common > application/authentication', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export {}
|
@ -7,3 +7,5 @@ describe('Page > /404', () => {
|
|||||||
cy.get('[data-cy=status-code]').contains('404')
|
cy.get('[data-cy=status-code]').contains('404')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export {}
|
@ -7,3 +7,5 @@ describe('Page > /500', () => {
|
|||||||
cy.get('[data-cy=status-code]').contains('500')
|
cy.get('[data-cy=status-code]').contains('500')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export {}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user