-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(UserSettingPage): settings page
- Loading branch information
1 parent
c31e3fb
commit 62b6f04
Showing
28 changed files
with
275 additions
and
20 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
prisma/migrations/20231102125908_user_settings/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- CreateTable | ||
CREATE TABLE "UserSettings" ( | ||
"id" TEXT NOT NULL, | ||
"userId" INTEGER NOT NULL, | ||
"theme" TEXT NOT NULL DEFAULT 'system', | ||
|
||
CONSTRAINT "UserSettings_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "UserSettings_userId_key" ON "UserSettings"("userId"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "UserSettings" ADD CONSTRAINT "UserSettings_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"No grade options in database": "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* eslint-disable */ | ||
// Do not edit, use generator to update | ||
import { i18n, fmt, I18nLangSet } from 'easy-typed-intl'; | ||
import getLang from '../../../utils/getLang'; | ||
|
||
import en from './en.json'; | ||
import ru from './ru.json'; | ||
|
||
export type I18nKey = keyof typeof en & keyof typeof ru; | ||
type I18nLang = 'en' | 'ru'; | ||
|
||
const keyset: I18nLangSet<I18nKey> = {}; | ||
|
||
keyset['en'] = en; | ||
keyset['ru'] = ru; | ||
|
||
export const tr = i18n<I18nLang, I18nKey>(keyset, fmt, getLang); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"No grade options in database": "Нет грейдов в базе данных" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import styled from 'styled-components'; | ||
import { gapM, gray4 } from '@taskany/colors'; | ||
|
||
interface PageSepProps { | ||
width?: number; | ||
} | ||
|
||
export const PageSep = styled.div<PageSepProps>` | ||
border-top: 1px solid ${gray4}; | ||
margin: ${gapM} 0; | ||
width: ${({ width }) => (width ? `${width}px` : 'auto')}; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { FormCard } from '@taskany/bricks'; | ||
import { danger0, gapL, gray4, warn0 } from '@taskany/colors'; | ||
import styled from 'styled-components'; | ||
|
||
type SettingsCardViewType = 'default' | 'warning' | 'danger'; | ||
|
||
const colorsMap: Record<SettingsCardViewType, string> = { | ||
default: gray4, | ||
warning: warn0, | ||
danger: danger0, | ||
}; | ||
|
||
export const SettingsContainer = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
gap: ${gapL}; | ||
margin: 0 ${gapL}; | ||
max-width: 850px; | ||
`; | ||
|
||
export const SettingsCard = styled(FormCard)<{ view?: SettingsCardViewType }>` | ||
border-color: ${({ view = 'default' }) => colorsMap[view]}; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { User, UserSettings } from 'prisma/prisma-client'; | ||
import { useTheme } from 'next-themes'; | ||
import { Fieldset, Form, FormRadio, FormRadioInput } from '@taskany/bricks'; | ||
|
||
import { SettingsCard, SettingsContainer } from '../Settings'; | ||
import { Theme, themes } from '../../utils/theme'; | ||
import { LayoutMain } from '../layout/LayoutMain'; | ||
import { PageSep } from '../PageSep'; | ||
import { trpc } from '../../utils/trpc-front'; | ||
import { useEditUserSettings } from '../../hooks/user-hooks'; | ||
|
||
import { tr } from './settings.i18n'; | ||
|
||
interface UserSettingPageBaseProps { | ||
user: User; | ||
settings: UserSettings; | ||
} | ||
|
||
export const UserSettingsPageBase = ({ user, settings }: UserSettingPageBaseProps) => { | ||
const { setTheme } = useTheme(); | ||
|
||
const editUserSettings = useEditUserSettings(); | ||
|
||
const onThemeChange = (theme: Theme) => { | ||
editUserSettings.mutateAsync({ theme }); | ||
setTheme(theme); | ||
}; | ||
|
||
return ( | ||
<LayoutMain pageTitle={user.name || user.email}> | ||
<PageSep /> | ||
|
||
<SettingsContainer> | ||
<SettingsCard> | ||
<Form> | ||
<Fieldset title={tr('Appearance')}> | ||
<FormRadio | ||
label={tr('Theme')} | ||
name="theme" | ||
value={settings.theme} | ||
onChange={(v) => onThemeChange(v as Theme)} | ||
> | ||
{themes.map((t) => ( | ||
<FormRadioInput key={t} value={t} label={t} /> | ||
))} | ||
</FormRadio> | ||
</Fieldset> | ||
</Form> | ||
</SettingsCard> | ||
</SettingsContainer> | ||
</LayoutMain> | ||
); | ||
}; | ||
|
||
interface UserSettingPageProps { | ||
userId: number; | ||
} | ||
|
||
export const UserSettingsPage = ({ userId }: UserSettingPageProps) => { | ||
const userQuery = trpc.users.getById.useQuery(userId); | ||
const user = userQuery.data; | ||
|
||
const settingsQuery = trpc.users.getSettings.useQuery(); | ||
const settings = settingsQuery.data; | ||
|
||
if (!user || !settings) return null; | ||
|
||
return <UserSettingsPageBase user={user} settings={settings} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"Appearance": "", | ||
"Theme": "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* eslint-disable */ | ||
// Do not edit, use generator to update | ||
import { i18n, fmt, I18nLangSet } from 'easy-typed-intl'; | ||
import getLang from '../../../utils/getLang'; | ||
|
||
import en from './en.json'; | ||
import ru from './ru.json'; | ||
|
||
export type I18nKey = keyof typeof en & keyof typeof ru; | ||
type I18nLang = 'en' | 'ru'; | ||
|
||
const keyset: I18nLangSet<I18nKey> = {}; | ||
|
||
keyset['en'] = en; | ||
keyset['ru'] = ru; | ||
|
||
export const tr = i18n<I18nLang, I18nKey>(keyset, fmt, getLang); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"Appearance": "Интерфейс", | ||
"Theme": "Тема" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.