Compare commits

...

64 Commits

Author SHA1 Message Date
vchikalkin
e668f0ded2 apps/web: add BIGSTRING metaObject fieldType 2024-03-27 14:45:03 +03:00
vchikalkin
dc1c315702 apps/web: pass cookie to getConfig request 2024-02-22 10:52:26 +03:00
vchikalkin
4d5ab7fd36 apps/web: fix pass cookie to api request 2024-02-21 11:51:29 +03:00
vchikalkin
4733f2bb61 Form/Documents: show http error after upload document 2024-02-02 16:28:17 +03:00
vchikalkin
54df128e56 Form/Common: pass http errors 2024-02-02 15:25:50 +03:00
vchikalkin
08aee48f07 Form/Documents: reload page after upload files 2024-02-02 12:29:46 +03:00
vchikalkin
b6001ca466 Form/Common: fix reload page 2024-02-02 12:18:41 +03:00
vchikalkin
8ebf5ff249 Form/Common: block form on save 2024-02-02 11:54:18 +03:00
vchikalkin
a821906190 components/Form: combine imports 2024-02-01 18:27:12 +03:00
vchikalkin
be938b4d62 Form/Common: disable save button if form values are not changed 2024-02-01 18:17:23 +03:00
vchikalkin
381ba678d9 Form/Documents: disable buttons if no files are selected for upload 2024-02-01 18:09:15 +03:00
vchikalkin
7590352ba5 Form/Documents: reset InputFile components onClick cancel button 2024-02-01 18:02:20 +03:00
vchikalkin
2b9cdd0d73 Form/Common: pass handleRetract function to button 2024-02-01 15:13:55 +03:00
vchikalkin
c40eda7fd8 apps/web: add UploadFiles button 2024-01-30 12:50:05 +03:00
vchikalkin
cf60724068 apps/web: upgrade packages 2024-01-30 11:26:03 +03:00
vchikalkin
f97597d1fb ci: remove test empty file 2023-12-24 10:57:32 +03:00
vchikalkin
83317cd0d2 ci: add test empty file 2023-12-24 10:55:40 +03:00
vchikalkin
e1e12da730 apps/web: upgrade next 2023-12-24 10:47:12 +03:00
vchikalkin
e40d5488b9 Docker: fix pass env vars 2023-12-23 22:34:09 +03:00
vchikalkin
0a5be044b1 project: remove .env 2023-12-23 18:03:08 +03:00
vchikalkin
0f82f208d9 Revert "apps/web: Dockerfile: remove using dotenv"
This reverts commit 36e158cb19894f6ce40c2f6b3cc41e8106384900.
2023-12-23 16:53:24 +03:00
vchikalkin
4b9ba14ee4 Revert "docker-compose.yml: remove environment"
This reverts commit 566c362c8a01c2e9416214bcce6e333e06bf79d5.
2023-12-23 16:53:12 +03:00
vchikalkin
8bce97b40a Revert "apps/web: Dockerfile: revert RUN pnpm add -g turbo"
This reverts commit 782408da5ea41d6481fbb8a9ba9cf674416c86b2.
2023-12-23 16:53:01 +03:00
vchikalkin
782408da5e apps/web: Dockerfile: revert RUN pnpm add -g turbo 2023-12-23 16:36:36 +03:00
vchikalkin
566c362c8a docker-compose.yml: remove environment 2023-12-23 16:35:30 +03:00
vchikalkin
36e158cb19 apps/web: Dockerfile: remove using dotenv 2023-12-23 16:32:11 +03:00
vchikalkin
ef827fb73e apps/web: Dockerfile: remove COPY .env .env 2023-12-23 16:23:41 +03:00
vchikalkin
f611e561ac apps/web: again trying to fix environment variables 2023-12-23 15:50:07 +03:00
vchikalkin
780794c53f apps/web: fix pass USE_DEV_COLORS to client 2023-12-23 15:28:46 +03:00
vchikalkin
ae7faa2cbf revert .env file 2023-12-23 15:08:16 +03:00
vchikalkin
4502b05b6f Revert "project: remove .env"
This reverts commit 22da611c52a1acedb6bb8be07f5695a4e114e6c9.
2023-12-23 15:07:40 +03:00
vchikalkin
22da611c52 project: remove .env
docker-compose.yml: uncomment environment
2023-12-23 15:06:37 +03:00
vchikalkin
126643982b apps/web: fix pass USE_DEV_COLORS variable to client 2023-12-23 15:03:09 +03:00
vchikalkin
e033886097 apps/web: next.config.js: pass env 2023-12-23 14:46:48 +03:00
vchikalkin
6918fb3766 Revert "docker-compose.yml: comment environment"
This reverts commit e56285070eb149f60012f00d951334d27bbc867b.
2023-12-23 14:46:22 +03:00
vchikalkin
e56285070e docker-compose.yml: comment environment 2023-12-23 14:43:03 +03:00
vchikalkin
92c3b0ca02 project: add docker-compose.yml 2023-12-23 14:27:27 +03:00
vchikalkin
b7c2cc0ff2 apps/web: fix Elements nullish values 2023-12-21 15:21:10 +03:00
vchikalkin
27d5fe4741 apps/web: simplify combineDocuments function 2023-11-30 16:39:08 +03:00
vchikalkin
a8d3c96d6d apps/web: combineDocuments: add missing documentTypes to res 2023-11-30 16:01:01 +03:00
vchikalkin
5f8a9c5320 apps/web: move getDocs function to server
rename getDocs -> combineDocuments
2023-11-30 15:53:49 +03:00
vchikalkin
74d5c11f8e apps/web: add canUpload prop to file 2023-11-30 15:40:08 +03:00
vchikalkin
6ffb48a3b9 apps/web: fix files list on mobile 2023-11-30 12:09:55 +03:00
vchikalkin
aaaa6fffbb apps/web: add close button to Overlay 2023-11-30 11:59:56 +03:00
vchikalkin
2ff3589715 apps/web: fix files map key 2023-11-30 11:55:27 +03:00
vchikalkin
55372c01b7 apps/web: show all documents in Files 2023-11-30 11:26:09 +03:00
vchikalkin
a5eb858f4a apps/web: hide download document button if no href 2023-11-30 10:49:07 +03:00
vchikalkin
498a64cdc9 apps/web: fix manifest 401 2023-11-28 13:01:50 +03:00
vchikalkin
24a12720d2 merge experimental/migrate-to-pnpm 2023-11-28 12:39:06 +03:00
vchikalkin
11bcb4257d apps/web: fix download buttons link 2023-11-28 09:49:05 +03:00
vchikalkin
0606a999ea apps/web: add download file feature 2023-11-27 15:56:44 +03:00
vchikalkin
ca521cbc22 apps/web: add files upload feature 2023-11-27 15:00:23 +03:00
vchikalkin
71d7a696f1 revert d625353 2023-11-27 14:28:32 +03:00
vchikalkin
40140c805e apps/web: disable api cache 2023-11-27 09:56:41 +03:00
vchikalkin
30d705a618 apps/web: use outline-secondary for retract button 2023-11-25 12:27:26 +03:00
vchikalkin
6c2e204499 apps/web: fix overlay layout 2023-11-24 10:31:16 +03:00
vchikalkin
39c13e9422 apps/web: fix layout 2023-11-23 17:06:58 +03:00
vchikalkin
c497890bcc packages/ui: button secondary colors improvements 2023-11-23 12:24:59 +03:00
vchikalkin
cb1306430d package/ui: allow to resize textarea 2023-11-22 16:50:22 +03:00
vchikalkin
12e36cd8ba apps/web: check comment exists in metaData 2023-11-22 15:40:59 +03:00
vchikalkin
a8684087cf packages/ui: add textarea
fix element container position
apps/web: add webkit scroll style
move comment element to end of form
use textarea element for comment
2023-11-22 15:36:08 +03:00
vchikalkin
c3b6e8b046 apps/web: reduce Buttons onClick timeout 2023-11-22 14:00:15 +03:00
vchikalkin
f497320558 apps/web: rename URL_IUS 2023-11-22 11:30:08 +03:00
vchikalkin
c83c0e5c51 apps/web: connect buttons to backend 2023-11-22 00:50:07 +03:00
63 changed files with 8481 additions and 6282 deletions

3
.env
View File

@ -1,3 +0,0 @@
USE_DEV_COLORS=
URL_IUS_DIRECT=

13
.gitignore vendored
View File

@ -1,9 +1,14 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies # Logs
node_modules logs
.pnp *.log
.pnp.js npm-debug.log*
# Dependency directory
**/node_modules/**
_node_modules
.pnp.cjs
# testing # testing
coverage coverage

View File

@ -31,5 +31,6 @@
"tailwindCSS.experimental.classRegex": [ "tailwindCSS.experimental.classRegex": [
["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"], ["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"],
["cx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"] ["cx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]
] ],
"editor.inlineSuggest.showToolbar": "always"
} }

View File

@ -18,9 +18,9 @@ This Turborepo includes the following packages/apps:
- `docs`: a [Next.js](https://nextjs.org/) app - `docs`: a [Next.js](https://nextjs.org/) app
- `web`: another [Next.js](https://nextjs.org/) app - `web`: another [Next.js](https://nextjs.org/) app
- `ui`: a stub React component library shared by both `web` and `docs` applications - `@repo/ui`: a stub React component library shared by both `web` and `docs` applications
- `eslint-config-custom`: `eslint` configurations (includes `eslint-config-next` and `eslint-config-prettier`) - `@repo/eslint-config`: `eslint` configurations (includes `eslint-config-next` and `eslint-config-prettier`)
- `tsconfig`: `tsconfig.json`s used throughout the monorepo - `@repo/tsconfig`: `tsconfig.json`s used throughout the monorepo
Each package/app is 100% [TypeScript](https://www.typescriptlang.org/). Each package/app is 100% [TypeScript](https://www.typescriptlang.org/).

View File

@ -1,16 +1,19 @@
FROM node:alpine AS builder FROM node:alpine AS builder
RUN corepack enable && corepack prepare pnpm@latest --activate
ENV PNPM_HOME=/usr/local/bin
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat RUN apk add --no-cache libc6-compat
RUN apk update RUN apk update
# Set working directory # Set working directory
WORKDIR /app WORKDIR /app
RUN yarn global add turbo RUN pnpm add -g turbo
RUN yarn global add dotenv-cli
COPY . . COPY . .
RUN turbo prune --scope=web --docker RUN turbo prune --scope=web --docker
# Add lockfile and package.json's of isolated subworkspace # Add lockfile and package.json's of isolated subworkspace
FROM node:alpine AS installer FROM node:alpine AS installer
RUN corepack enable && corepack prepare pnpm@latest --activate
ENV PNPM_HOME=/usr/local/bin
RUN apk add --no-cache libc6-compat RUN apk add --no-cache libc6-compat
RUN apk update RUN apk update
WORKDIR /app WORKDIR /app
@ -18,14 +21,16 @@ WORKDIR /app
# First install the dependencies (as they change less often) # First install the dependencies (as they change less often)
COPY .gitignore .gitignore COPY .gitignore .gitignore
COPY --from=builder /app/out/json/ . COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/yarn.lock ./yarn.lock COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
RUN yarn install COPY --from=builder /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml
RUN pnpm install
# Build the project # Build the project
COPY --from=builder /app/out/full/ . COPY --from=builder /app/out/full/ .
COPY turbo.json turbo.json COPY turbo.json turbo.json
COPY .env .env ARG URL_IUS_DIRECT
RUN yarn dotenv -e .env turbo run build --filter=web... ARG NEXT_PUBLIC_USE_DEV_COLORS
RUN pnpm turbo run build --filter=web...
FROM node:alpine AS runner FROM node:alpine AS runner
WORKDIR /app WORKDIR /app

View File

@ -1,4 +1,3 @@
'use server';
import type * as t from './types'; import type * as t from './types';
import { getUrls } from '@/config/urls'; import { getUrls } from '@/config/urls';
import { createUrl, type PageUrlParams } from '@/utils/url'; import { createUrl, type PageUrlParams } from '@/utils/url';
@ -6,55 +5,116 @@ import type { WretchError } from 'wretch';
import wretch from 'wretch'; import wretch from 'wretch';
const urls = getUrls(); const urls = getUrls();
const api = wretch(urls.URL_UIS).errorType('json'); const api = wretch(urls.URL_IUS).options({ cache: 'no-store' }).errorType('json');
type Input = { pageUrlParams: PageUrlParams; payload?: unknown }; type Input = { cookie?: string; pageUrlParams: PageUrlParams; payload?: unknown };
export async function getData({ pageUrlParams }: Input) { export async function getData({ pageUrlParams, cookie = '' }: Input) {
const url = createUrl({ const url = createUrl({
...pageUrlParams, ...pageUrlParams,
route: '', route: '',
}); });
return api return api
.headers({ cookie })
.get(url) .get(url)
.res<t.ResponseGetData>((cb) => cb.json()) .res<t.ResponseGetData>((cb) => cb.json())
.then((res) => res); .then((res) => res);
} }
export async function getMetaData({ pageUrlParams }: Input) { export async function getMetaData({ pageUrlParams, cookie = '' }: Input) {
const url = createUrl({ ...pageUrlParams, route: '/meta' }); const url = createUrl({ ...pageUrlParams, route: '/meta' });
return api return api
.headers({ cookie })
.get(url) .get(url)
.res<t.ResponseMetaData>((res) => res.json()) .res<t.ResponseMetaData>((res) => res.json())
.then((res) => res); .then((res) => res);
} }
export async function getConfig({ pageUrlParams }: Input) { export async function getConfig({ pageUrlParams, cookie = '' }: Input) {
const url = createUrl({ ...pageUrlParams, route: '/config' }); const url = createUrl({ ...pageUrlParams, route: '/config' });
return api return api
.headers({ cookie })
.get(url) .get(url)
.res<t.ResponseConfig>((res) => res.json()) .res<t.ResponseConfig>((res) => res.json())
.then((res) => res); .then((res) => res);
} }
export async function getConditions({ pageUrlParams }: Input) { export async function getConditions({ pageUrlParams, cookie = '' }: Input) {
const url = createUrl({ ...pageUrlParams, route: '/conditions' }); const url = createUrl({ ...pageUrlParams, route: '/conditions' });
return api return api
.headers({ cookie })
.get(url) .get(url)
.res<t.ResponseConditions>((res) => res.text()) .res<t.ResponseConditions>((res) => res.text())
.then((res) => res); .then((res) => res);
} }
export async function validate({ pageUrlParams, payload }: Input) { export async function save({ pageUrlParams, payload }: Input) {
const url = createUrl({ ...pageUrlParams, route: '/validate' }); const url = createUrl({ ...pageUrlParams, route: '/transfer' });
return api return api
.post(payload, url) .post(payload, url)
.res<boolean>((res) => res.ok) .res<boolean>((res) => res.ok)
.then((res) => res) .then((res) => res)
.catch((error: WretchError) => error.json as t.HttpValidationError); .catch((error: WretchError) => error.json as t.HttpValidationError | t.HttpError);
}
export async function retract({ pageUrlParams, payload }: Input) {
const url = createUrl({ ...pageUrlParams, route: '/return' });
return api
.post(payload, url)
.res<boolean>((res) => res.ok)
.then((res) => res)
.catch((error: WretchError) => error.json as t.HttpValidationError | t.HttpError);
}
export async function getDocumentTypes({ pageUrlParams, cookie = '' }: Input) {
const url = createUrl({ ...pageUrlParams, route: '/documenttypes' });
return api
.headers({ cookie })
.get(url)
.res<t.ResponseDocumentTypes>((res) => res.json())
.then((res) => res);
}
export async function getDocuments({ pageUrlParams, cookie = '' }: Input) {
const url = createUrl({ ...pageUrlParams, route: '/documents' });
return api
.headers({ cookie })
.get(url)
.res<t.ResponseDocuments>((res) => res.json())
.then((res) => res);
}
export function uploadDocument({
pageUrlParams,
document,
formData,
}: Input & { document: Pick<t.DocumentType, 'documentTypeId'>; formData: FormData }) {
const url = createUrl({
...pageUrlParams,
route: '/document',
urlSearchParams: { ...pageUrlParams.urlSearchParams, ...document },
});
return fetch(urls.URL_IUS + url, {
body: formData,
method: 'POST',
})
.then((res) => {
if (res.ok) {
return true;
}
return res.json();
})
.catch((error) => {
throw error as t.HttpError;
});
} }

34
apps/web/api/ius/tools.ts Normal file
View File

@ -0,0 +1,34 @@
import type { Document, DocumentType } from './types';
export function combineDocuments({
documentTypes,
documents,
}: {
documentTypes: DocumentType[];
documents: Document[];
}) {
if (!documents.length) {
return documentTypes.map((x) => ({ ...(x as Document), canUpload: true }));
}
const nonUploadableDocuments = documents
.filter(
(document) =>
!documentTypes.some(
(documentType) => documentType.documentTypeId === document.documentTypeId
)
)
.map((document) => ({ ...document, canUpload: false }));
return documentTypes
.map((documentType) => {
const targetDocument = documents.find(
(document) => document.documentTypeId === documentType.documentTypeId
);
return { ...documentType, ...targetDocument, canUpload: true };
})
.concat(nonUploadableDocuments);
}
export type CombinedDocuments = ReturnType<typeof combineDocuments>;

View File

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
export type MetaObject = { export type MetaObject = {
disabled: boolean; disabled: boolean;
fieldType: 'CHECKBOX' | 'DECIMAL' | 'INT' | 'STRING'; fieldType: 'CHECKBOX' | 'DECIMAL' | 'INT' | 'STRING' | 'BIGSTRING';
label: string; label: string;
max: number; max: number;
min: number; min: number;
@ -11,10 +11,22 @@ export type MetaObject = {
type Value = any; type Value = any;
export type DocumentType = {
documentTypeId: string;
name: string;
};
export type Document = DocumentType & {
documentId?: string;
href?: string;
};
export type ResponseGetData = Record<string, Value>; export type ResponseGetData = Record<string, Value>;
export type ResponseMetaData = Record<string, MetaObject>; export type ResponseMetaData = Record<string, MetaObject>;
export type ResponseConfig = { title: string }; export type ResponseConfig = { title: string };
export type ResponseConditions = string; export type ResponseConditions = string;
export type ResponseDocumentTypes = DocumentType[];
export type ResponseDocuments = Document[];
export type HttpError = { export type HttpError = {
errors: string[]; errors: string[];

View File

@ -18,3 +18,24 @@
body { body {
background-color: var(--color-background); background-color: var(--color-background);
} }
/* Scroll bar stylings */
::-webkit-scrollbar {
width: 6px;
height: 6px;
}
/* Track */
::-webkit-scrollbar-track {
}
/* Handle */
::-webkit-scrollbar-thumb {
background: rgba(0, 0, 0, 0.3);
border-radius: 2px;
}
/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
background: rgba(0, 0, 0, 0.4);
}

View File

@ -4,10 +4,14 @@ import type { PageProps } from '@/types/page';
import { withError } from '@/utils/error'; import { withError } from '@/utils/error';
import { getPageUrlParams } from '@/utils/url'; import { getPageUrlParams } from '@/utils/url';
import type { Metadata } from 'next'; import type { Metadata } from 'next';
import { headers } from 'next/headers';
export async function generateMetadata(pageProps: PageProps): Promise<Metadata> { export async function generateMetadata(pageProps: PageProps): Promise<Metadata> {
const pageUrlParams = getPageUrlParams(pageProps); const pageUrlParams = getPageUrlParams(pageProps);
const { title } = await apiIUS.getConfig({ pageUrlParams }); const headersList = headers();
const cookie = headersList.get('cookie') ?? '';
const { title } = await apiIUS.getConfig({ cookie, pageUrlParams });
const text = `Условия: ${title} | Эволюция`; const text = `Условия: ${title} | Эволюция`;
return { return {
@ -24,7 +28,10 @@ export default async function Page(pageProps: PageProps) {
return withError({ return withError({
render: async () => { render: async () => {
const pageUrlParams = getPageUrlParams(pageProps); const pageUrlParams = getPageUrlParams(pageProps);
const conditions = await apiIUS.getConditions({ pageUrlParams }); const headersList = headers();
const cookie = headersList.get('cookie') ?? '';
const conditions = await apiIUS.getConditions({ cookie, pageUrlParams });
return <Conditions html={conditions} />; return <Conditions html={conditions} />;
}, },

View File

@ -1,13 +1,19 @@
import * as apiIUS from '@/api/ius/query'; import * as apiIUS from '@/api/ius/query';
import { combineDocuments } from '@/api/ius/tools';
import { Form } from '@/components/Form'; import { Form } from '@/components/Form';
import type { FormComponentProps } from '@/components/Form/types';
import type { PageProps } from '@/types/page'; import type { PageProps } from '@/types/page';
import { withError } from '@/utils/error'; import { withError } from '@/utils/error';
import { getPageUrlParams } from '@/utils/url'; import { getPageUrlParams } from '@/utils/url';
import type { Metadata } from 'next'; import type { Metadata } from 'next';
import { headers } from 'next/headers';
export async function generateMetadata(pageProps: PageProps): Promise<Metadata> { export async function generateMetadata(pageProps: PageProps): Promise<Metadata> {
const pageUrlParams = getPageUrlParams(pageProps); const pageUrlParams = getPageUrlParams(pageProps);
const { title } = await apiIUS.getConfig({ pageUrlParams }); const headersList = headers();
const cookie = headersList.get('cookie') ?? '';
const { title } = await apiIUS.getConfig({ cookie, pageUrlParams });
const text = `${title} | Эволюция`; const text = `${title} | Эволюция`;
return { return {
@ -25,12 +31,24 @@ export default async function Page(pageProps: PageProps) {
render: async () => { render: async () => {
const pageUrlParams = getPageUrlParams(pageProps); const pageUrlParams = getPageUrlParams(pageProps);
const headersList = headers();
const cookie = headersList.get('cookie') ?? '';
return Promise.all([ return Promise.all([
apiIUS.getData({ pageUrlParams }), apiIUS.getData({ cookie, pageUrlParams }),
apiIUS.getMetaData({ pageUrlParams }), apiIUS.getMetaData({ cookie, pageUrlParams }),
apiIUS.getConfig({ pageUrlParams }), apiIUS.getConfig({ cookie, pageUrlParams }),
]).then(([data, metaData, { title }]) => { apiIUS.getDocumentTypes({ cookie, pageUrlParams }),
const props = { data, metaData, pageUrlParams, title }; apiIUS.getDocuments({ cookie, pageUrlParams }),
]).then(([data, metaData, { title }, documentTypes, documents]) => {
const combinedDocuments = combineDocuments({ documentTypes, documents });
const props: FormComponentProps = {
combinedDocuments,
data,
metaData,
pageUrlParams,
title,
};
return <Form {...props} />; return <Form {...props} />;
}); });

View File

@ -1,9 +1,9 @@
import './globals.css'; import './globals.css';
import { Auth, Logo } from '@/components/layout'; import { Auth, Logo } from '@/components/layout';
import { Controls } from '@/components/layout/controls'; import { Controls } from '@/components/layout/controls';
import { Content, Header } from '@repo/ui';
import type { Metadata } from 'next'; import type { Metadata } from 'next';
import localFont from 'next/font/local'; import localFont from 'next/font/local';
import { Content, Header } from 'ui';
const inter = localFont({ const inter = localFont({
src: [ src: [
@ -46,16 +46,17 @@ export default function RootLayout({ children }: { readonly children: React.Reac
<head> <head>
<meta charSet="utf-8" /> <meta charSet="utf-8" />
<meta name="theme-color" content="#000000" /> <meta name="theme-color" content="#000000" />
<link rel="manifest" href="/manifest.webmanifest" crossOrigin="use-credentials" />
</head> </head>
<body className={inter.className}> <body className={inter.className}>
<Header> <Header>
<Logo /> <Logo />
<Auth /> <Auth />
</Header> </Header>
<div className="flex flex-col items-center "> <Content>
<Controls /> <Controls />
<Content>{children}</Content> {children}
</div> </Content>
</body> </body>
</html> </html>
); );

View File

@ -1,25 +0,0 @@
import type { MetadataRoute } from 'next';
export default function manifest(): MetadataRoute.Manifest {
return {
background_color: '#fff',
description: 'External | Эволюция',
display: 'standalone',
icons: [
{
sizes: '192x192',
src: '/android-chrome-192x192.png',
type: 'image/png',
},
{
sizes: '512x512',
src: '/android-chrome-512x512.png',
type: 'image/png',
},
],
name: 'External | Эволюция',
short_name: 'External | Эволюция',
start_url: '/',
theme_color: '#fff',
};
}

View File

@ -1,4 +1,4 @@
import { HttpError } from 'ui'; import { HttpError } from '@repo/ui';
export default function NotFound() { export default function NotFound() {
return <HttpError code="404" title="Страница не найдена" />; return <HttpError code="404" title="Страница не найдена" />;

View File

@ -1,4 +1,4 @@
import { Background } from 'ui'; import { Background } from '@repo/ui';
type Props = { type Props = {
readonly html: string; readonly html: string;
@ -8,7 +8,7 @@ export function Conditions({ html }: Props) {
return ( return (
<Background <Background
dangerouslySetInnerHTML={{ __html: html }} dangerouslySetInnerHTML={{ __html: html }}
className="lg:w-standard grid w-full justify-center p-5 font-[calibri]" className="grid w-full justify-center p-5 font-[calibri]"
/> />
); );
} }

View File

@ -1,46 +0,0 @@
import { FormContext } from './context/form-context';
import * as apiIus from '@/api/ius/query';
import { useFormStore } from '@/store/ius/form';
import { useContext } from 'react';
import { Button } from 'ui';
export function Buttons() {
const { reset, setValidation, values } = useFormStore();
const { pageUrlParams, setFormStatus } = useContext(FormContext);
return (
<div className="grid grid-cols-1 gap-2 gap-x-4 md:grid-cols-3">
<Button
intent="outline-danger"
onClick={() => {
reset();
}}
>
Отмена
</Button>
<Button
intent="secondary"
onClick={() => {
setFormStatus('pending');
}}
>
Возврат на доработку
</Button>
<Button
onClick={() => {
apiIus.validate({ pageUrlParams, payload: values }).then((res) => {
if (typeof res !== 'boolean') {
Object.keys(res.errors).forEach((name) => {
const elementValidation = res?.errors?.[name];
if (elementValidation)
setValidation({ message: elementValidation[0] ?? '', name, valid: false });
});
}
});
}}
>
Сохранить
</Button>
</div>
);
}

View File

@ -0,0 +1,95 @@
/* eslint-disable react/jsx-curly-newline */
/* eslint-disable no-negated-condition */
import { FormContext } from '../context/form-context';
import * as apiIus from '@/api/ius/query';
import { useFormStore } from '@/store/ius/form';
import { Button } from '@repo/ui';
import { useCallback, useContext } from 'react';
const ERROR_RETRACT = 'Произошла ошибка при возврате на доработку';
const ERROR_SAVE = 'Произошла ошибка при сохранении';
export function Buttons() {
const { reset, resetValidation, setValidation, status, values } = useFormStore();
const { pageUrlParams, setFormState } = useContext(FormContext);
const handleSave = useCallback(() => {
setFormState({ status: 'pending' });
resetValidation();
apiIus.save({ pageUrlParams, payload: values }).then((res) => {
if (typeof res !== 'boolean') {
const { errors } = res;
if (Array.isArray(errors)) {
setFormState({ status: 'error', text: errors?.at(0) || ERROR_SAVE });
return;
}
Object.keys(errors).forEach((name) => {
const elementValidation = errors?.[name];
if (elementValidation)
setValidation({ message: elementValidation[0] ?? '', name, valid: false });
});
setTimeout(() => {
setFormState({ status: 'edit' });
}, 300);
} else {
setFormState({ status: 'success' });
setTimeout(() => {
window.location.reload();
}, 500);
}
});
}, [pageUrlParams, resetValidation, setFormState, setValidation, values]);
const handleRetract = useCallback(() => {
setFormState({ status: 'pending' });
resetValidation();
apiIus.retract({ pageUrlParams, payload: values }).then((res) => {
if (typeof res !== 'boolean') {
const { errors } = res;
if (Array.isArray(errors)) {
setFormState({ status: 'error', text: errors?.at(0) || ERROR_RETRACT });
return;
}
setTimeout(() => {
setFormState({ status: 'edit' });
}, 300);
Object.keys(errors).forEach((name) => {
const elementValidation = errors?.[name];
if (elementValidation)
setValidation({ message: elementValidation[0] ?? '', name, valid: false });
});
} else {
setFormState({ status: 'success' });
setTimeout(() => {
window.location.reload();
}, 500);
}
});
}, [pageUrlParams, resetValidation, setFormState, setValidation, values]);
return (
<div className="grid grid-cols-1 gap-2 gap-x-4 md:grid-cols-3">
<Button
intent="outline-danger"
onClick={() => {
reset();
}}
>
Отмена
</Button>
<Button intent="outline-secondary" onClick={handleRetract}>
Возврат на доработку
</Button>
<Button onClick={handleSave} disabled={status !== 'edited'}>
Сохранить
</Button>
</div>
);
}

View File

@ -0,0 +1,79 @@
import type { FormComponentProps } from '../types';
import type { MetaObject } from '@/api/ius/types';
import { mapFieldTypeElement } from '@/config/elements';
import { useFormStore } from '@/store/ius/form';
import { ElementContainer } from '@repo/ui';
import { get } from 'radash';
import { useEffect } from 'react';
function RenderElement({
fieldType,
label,
max,
min = 0,
name,
visible,
...props
}: MetaObject & { readonly name: string }) {
const { setValue, validation, values } = useFormStore();
if (!visible) return false;
const Element = mapFieldTypeElement[fieldType];
return (
<ElementContainer
intent={validation[name] ? 'danger' : 'default'}
message={validation[name]?.message}
key={name}
id={name}
title={label}
>
<Element
loading={!Object.keys(values).length}
checked={fieldType === 'CHECKBOX' ? Boolean(values[name]) ?? false : false}
id={name}
value={values[name] ?? ''}
min={min}
max={max}
onChange={(e) => {
setValue({
name,
value:
fieldType === 'CHECKBOX' ? (e.target as HTMLInputElement).checked : e.target.value,
});
}}
{...props}
/>
</ElementContainer>
);
}
export function Elements({ data, metaData }: FormComponentProps) {
const { init } = useFormStore();
useEffect(() => {
init(data);
}, [data, init]);
const defaultElements = Object.keys(metaData).filter(
(x) => metaData[x]?.fieldType !== 'BIGSTRING'
);
const bigStringElements = Object.keys(metaData).filter(
(x) => metaData[x]?.fieldType === 'BIGSTRING'
);
return (
<>
<div className="mt-2 grid gap-2 gap-x-4 md:grid md:grid-cols-2 lg:grid-cols-3">
{defaultElements.map((name) => (
<RenderElement key={name} {...get(metaData, name)} name={name} />
))}
</div>
{bigStringElements.map((name) => (
<RenderElement key={name} {...get(metaData, name)} name={name} fieldType="BIGSTRING" />
))}
</>
);
}

View File

@ -0,0 +1,2 @@
export * from './Buttons';
export * from './Elements';

View File

@ -0,0 +1,76 @@
/* eslint-disable react/jsx-curly-newline */
/* eslint-disable no-negated-condition */
import { FormContext } from '../context/form-context';
import * as apiIus from '@/api/ius/query';
import type { HttpError } from '@/api/ius/types';
import { useFormStore } from '@/store/ius/form';
import { Button } from '@repo/ui';
import { pick } from 'radash';
import { useCallback, useContext } from 'react';
const ERROR_UPLOAD_DOCUMENT = 'Произошла ошибка при загрузке документов';
const SUCCESS_UPLOAD_DOCUMENTS = 'Файлы успешно загружены';
export function Buttons() {
const { resetValidation } = useFormStore();
const { formFiles, pageUrlParams, setFormFiles, setFormState } = useContext(FormContext);
const handleUploadFiles = useCallback(() => {
setFormState({ status: 'pending' });
resetValidation();
const uploadFiles = formFiles.map((formFile) => {
const formData = new FormData();
formData.append('file', formFile.file);
const document = pick(formFile, ['documentTypeId']);
return apiIus.uploadDocument({
document,
formData,
pageUrlParams,
});
});
return Promise.all(uploadFiles)
.then(async (res) => {
const errors = res.filter((x) => typeof x !== 'boolean') as HttpError[];
if (!errors.length) {
setFormState({
status: 'success',
text: SUCCESS_UPLOAD_DOCUMENTS,
});
setTimeout(() => {
window.location.reload();
}, 500);
return;
}
const error = errors.find((x) => x.errors.length)?.errors.at(0) || ERROR_UPLOAD_DOCUMENT;
setFormState({ status: 'error', text: error });
})
.catch((error) => {
setFormState({
status: 'error',
text: error ? JSON.stringify(error) : ERROR_UPLOAD_DOCUMENT,
});
});
}, [formFiles, pageUrlParams, resetValidation, setFormState]);
const handleCancel = () => {
setFormFiles([]);
};
return (
<div className="grid grid-cols-1 gap-2 gap-x-4 md:grid-cols-3">
<Button intent="outline-danger" onClick={handleCancel} disabled={!formFiles.length}>
Отмена
</Button>
<Button onClick={handleUploadFiles} disabled={!formFiles.length}>
Загрузить файлы
</Button>
</div>
);
}

View File

@ -0,0 +1,75 @@
import { FormContext } from '../context/form-context';
import type { FormComponentProps } from '../types';
import { ArrowDownTrayIcon } from '@heroicons/react/24/solid';
import { Heading, InputFile } from '@repo/ui';
import Link from 'next/link';
import { useContext, useEffect, useRef } from 'react';
type DownloadDocumentProps = Pick<FileProps, 'document'>;
function DownloadDocument({ document }: DownloadDocumentProps) {
return document?.href ? (
<Link
href={'/api/ius' + document.href}
target="_blank"
rel="noopener noreferrer"
className="text-primary-600 h-10 px-5 py-2.5 text-sm font-medium hover:underline"
>
<div className="flex flex-row items-center gap-1">
<ArrowDownTrayIcon className="h-4 w-4" />
Скачать
</div>
</Link>
) : (
false
);
}
type FileProps = {
readonly document: FormComponentProps['combinedDocuments'][number];
};
function File({ document }: FileProps) {
const { formFiles, setFormFiles } = useContext(FormContext);
const { canUpload, documentTypeId, name } = document;
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
if (event.target.files !== null) {
const file = event.target.files.item(0);
if (file)
setFormFiles([
...formFiles.filter((x) => x.documentTypeId !== documentTypeId),
{ documentTypeId, file, name },
]);
}
};
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
const uploadableFile = formFiles.some((x) => x.documentTypeId === document.documentTypeId);
if (!uploadableFile && inputRef.current) inputRef.current.value = '';
}, [document.documentTypeId, formFiles]);
return (
<div key={documentTypeId} className="flex flex-col gap-1">
<label className="mb-2 block text-sm font-normal text-gray-900">{name}:</label>
<InputFile ref={inputRef} onChange={handleFileChange} disabled={!canUpload} />
<DownloadDocument document={document} />
</div>
);
}
export function Files({ combinedDocuments }: FormComponentProps) {
return (
<div className="grid gap-4">
<Heading className="text-sm">Документы</Heading>
<div className="grid gap-2 md:grid-cols-2">
{combinedDocuments.map((document) => (
<File key={document.documentTypeId} document={document} />
))}
</div>
</div>
);
}

View File

@ -0,0 +1,2 @@
export * from './Buttons';
export * from './Files';

View File

@ -1,51 +0,0 @@
import type { Props } from './types';
import { mapFieldTypeElement } from '@/config/elements';
import { useFormStore } from '@/store/ius/form';
import { useEffect } from 'react';
import { ElementContainer } from 'ui';
export function Elements({ data, metaData }: Props) {
const { init, setValue, validation, values } = useFormStore();
useEffect(() => {
init(data);
}, [data, init]);
return (
<div className="mt-2 grid auto-rows-auto grid-cols-1 gap-2 gap-x-4 md:grid-cols-2 lg:grid-cols-3">
{Object.keys(metaData).map((name) => {
const { fieldType, label, max, min = 0, visible, ...props } = metaData[name];
if (!visible) return false;
const Element = mapFieldTypeElement[fieldType];
return (
<ElementContainer
intent={validation[name] ? 'danger' : 'default'}
message={validation[name]?.message}
key={name}
id={name}
title={label}
>
<Element
loading={!Object.keys(values).length}
checked={fieldType === 'CHECKBOX' ? Boolean(values[name]) || false : false}
id={name}
value={values[name] || ''}
min={min}
max={max}
onChange={(e) => {
setValue({
name,
value: fieldType === 'CHECKBOX' ? e.target.checked : e.target.value,
});
}}
{...props}
/>
</ElementContainer>
);
})}
</div>
);
}

View File

@ -1,9 +1,9 @@
import { Heading } from '@repo/ui';
import Link from 'next/link'; import Link from 'next/link';
import { Heading } from 'ui';
export function Header({ link, title }: { readonly link: string; readonly title: string }) { export function Header({ link, title }: { readonly link: string; readonly title: string }) {
return ( return (
<div className="flex justify-between"> <div className="flex flex-col justify-between md:flex-row">
<Heading size={2}>{title}</Heading> <Heading size={2}>{title}</Heading>
<Link href={link} className="text-primary-600 text-sm font-medium hover:underline" prefetch> <Link href={link} className="text-primary-600 text-sm font-medium hover:underline" prefetch>
Посмотреть условия Посмотреть условия

View File

@ -1,33 +1,61 @@
'use client'; 'use client';
import { FormContext } from './context/form-context'; import { FormContext } from './context/form-context';
import { CheckCircleIcon } from '@heroicons/react/24/solid'; import { CheckCircleIcon, XCircleIcon } from '@heroicons/react/24/solid';
import { Background, Button, LoadingSpinner } from '@repo/ui';
import type { PropsWithChildren } from 'react'; import type { PropsWithChildren } from 'react';
import { useContext } from 'react'; import { useContext } from 'react';
import { Background, LoadingSpinner } from 'ui';
function OverlayWrapper({ children }: PropsWithChildren) { function OverlayWrapper({ children }: PropsWithChildren) {
return ( return (
<Background className="lg:w-standard absolute grid h-full w-full items-center justify-center border-none bg-opacity-80 backdrop-blur-sm"> <Background className="absolute left-0 top-0 grid h-full w-full place-items-center bg-opacity-80 backdrop-blur-sm">
<div className="flex flex-row items-center gap-2">{children} </div> <div className="absolute bottom-[50vh] flex flex-col items-center gap-2 md:relative md:bottom-0">
{children}
</div>
</Background> </Background>
); );
} }
export function Overlay() {
const { formStatus } = useContext(FormContext);
if (formStatus === 'pending') function StateContentWrapper({ children }: PropsWithChildren) {
return ( return <div className="flex flex-row items-center gap-2">{children}</div>;
<OverlayWrapper> }
{LoadingSpinner} <p className="font-medium">Загрузка...</p>
</OverlayWrapper> export function Overlay() {
); const { formState, setFormState } = useContext(FormContext);
if (formStatus === 'success') const { status, text } = formState;
return (
<OverlayWrapper> let stateContent: JSX.Element | false = false;
<CheckCircleIcon className="h-10 w-10 fill-green-500" title="OK" />{' '}
<p className="font-medium">Данные сохранены</p> if (status === 'pending') {
</OverlayWrapper> stateContent = (
); <StateContentWrapper>
{LoadingSpinner} <p className="font-medium">Загрузка...</p>
return false; </StateContentWrapper>
);
}
if (status === 'success') {
stateContent = (
<StateContentWrapper>
<CheckCircleIcon className="h-10 w-10 fill-green-500" title="OK" />
<p className="font-medium">Данные сохранены</p>
</StateContentWrapper>
);
}
if (status === 'error') {
stateContent = (
<>
<StateContentWrapper>
<XCircleIcon className="h-10 w-10 fill-red-500" title="Error" />
<p className="font-medium">{text}</p>
</StateContentWrapper>{' '}
<Button type="button" intent="text" onClick={() => setFormState({ status: 'edit' })}>
Закрыть
</Button>
</>
);
}
if (!stateContent) return false;
return <OverlayWrapper>{stateContent}</OverlayWrapper>;
} }

View File

@ -1,13 +1,19 @@
import type { DocumentType } from '@/api/ius/types';
import type { PageUrlParams } from '@/utils/url'; import type { PageUrlParams } from '@/utils/url';
import type { PropsWithChildren } from 'react'; import type { PropsWithChildren } from 'react';
import { createContext, useMemo, useState } from 'react'; import { createContext, useMemo, useState } from 'react';
type FormStatus = 'pending' | 'edit' | 'success'; type FormStatus = 'pending' | 'edit' | 'success' | 'error';
type FormState = { status: FormStatus; text?: string };
type FormFile = DocumentType & { file: File };
type ContextType = { type ContextType = {
readonly formStatus: FormStatus; readonly formFiles: FormFile[];
readonly formState: FormState;
readonly pageUrlParams: PageUrlParams; readonly pageUrlParams: PageUrlParams;
readonly setFormStatus: (status: FormStatus) => void; readonly setFormFiles: (files: FormFile[]) => void;
readonly setFormState: (formState: FormState) => void;
}; };
export const FormContext = createContext<ContextType>({} as ContextType); export const FormContext = createContext<ContextType>({} as ContextType);
@ -16,10 +22,11 @@ export function FormContextProvider({
children, children,
...initialData ...initialData
}: PropsWithChildren & Pick<ContextType, 'pageUrlParams'>) { }: PropsWithChildren & Pick<ContextType, 'pageUrlParams'>) {
const [formStatus, setFormStatus] = useState<FormStatus>('edit'); const [formState, setFormState] = useState<FormState>({ status: 'edit' });
const [formFiles, setFormFiles] = useState<FormFile[]>([]);
const value = useMemo( const value = useMemo(
() => ({ ...initialData, formStatus, setFormStatus }), () => ({ ...initialData, formFiles, formState, setFormFiles, setFormState }),
[formStatus, initialData] [formFiles, formState, initialData]
); );
return <FormContext.Provider value={value}>{children}</FormContext.Provider>; return <FormContext.Provider value={value}>{children}</FormContext.Provider>;

View File

@ -1,31 +1,34 @@
'use client'; 'use client';
import { Buttons } from './Buttons'; import * as Common from './Common';
import { FormContext, FormContextProvider } from './context/form-context'; import { FormContext, FormContextProvider } from './context/form-context';
import { Elements } from './Elements'; import * as Documents from './Documents';
import { Header } from './Header'; import { Header } from './Header';
import { Overlay } from './Overlay'; import { Overlay } from './Overlay';
import type { Props } from './types'; import type { FormComponentProps } from './types';
import { createUrl } from '@/utils/url'; import { createUrl } from '@/utils/url';
import { Background, Divider } from '@repo/ui';
import type { FC } from 'react'; import type { FC } from 'react';
import { useContext } from 'react'; import { useContext } from 'react';
import { Background, Divider } from 'ui';
function Content(props: Props) { function Content(props: FormComponentProps) {
const { title } = props; const { title } = props;
const { pageUrlParams } = useContext(FormContext); const { pageUrlParams } = useContext(FormContext);
return ( return (
<Background className="lg:w-standard relative grid w-full gap-2 p-5"> <Background className="relative flex w-full flex-col gap-2 p-5">
<Overlay /> <Overlay />
<Header title={title} link={'/ius' + createUrl({ ...pageUrlParams, route: '/conditions' })} /> <Header title={title} link={'/ius' + createUrl({ ...pageUrlParams, route: '/conditions' })} />
<Elements {...props} /> <Common.Elements {...props} />
<Common.Buttons />
<Divider />
<Documents.Files {...props} />
<Documents.Buttons />
<Divider /> <Divider />
<Buttons />
</Background> </Background>
); );
} }
function withContext<T extends Props>(Component: FC<T>) { function withContext<T extends FormComponentProps>(Component: FC<T>) {
return (props: T) => { return (props: T) => {
const { pageUrlParams } = props; const { pageUrlParams } = props;

View File

@ -1,9 +1,11 @@
import type { ResponseGetData, ResponseMetaData } from '@/api/ius/types'; import type { CombinedDocuments } from '@/api/ius/tools';
import type * as IUS from '@/api/ius/types';
import type { PageUrlParams } from '@/utils/url'; import type { PageUrlParams } from '@/utils/url';
export type Props = { export type FormComponentProps = {
readonly data: ResponseGetData; readonly combinedDocuments: CombinedDocuments;
readonly metaData: ResponseMetaData; readonly data: IUS.ResponseGetData;
readonly metaData: IUS.ResponseMetaData;
readonly pageUrlParams: PageUrlParams; readonly pageUrlParams: PageUrlParams;
readonly title: string; readonly title: string;
}; };

View File

@ -6,7 +6,7 @@ export function Controls() {
const router = useRouter(); const router = useRouter();
return ( return (
<div className="lg:w-standard flex w-full flex-row px-5 pt-5"> <div className="flex w-full flex-row px-5 pt-5">
<button <button
className="flex flex-row items-center gap-2 text-sm" className="flex flex-row items-center gap-2 text-sm"
type="button" type="button"

View File

@ -1,10 +1,12 @@
import { getEnv } from '@/config/env'; import { getClientEnv } from '@/config/env';
import Image from 'next/image'; import Image from 'next/image';
import logo from 'public/assets/images/logo-primary.svg'; import logo from 'public/assets/images/logo-primary.svg';
import logoDev from 'public/assets/images/logo-primary-dev.svg'; import logoDev from 'public/assets/images/logo-primary-dev.svg';
const env = getEnv(); const env = getClientEnv();
export function Logo() { export function Logo() {
return <Image priority alt="logo" src={env.USE_DEV_COLORS ? logoDev : logo} height="24" />; return (
<Image priority alt="logo" src={env.NEXT_PUBLIC_USE_DEV_COLORS ? logoDev : logo} height="24" />
);
} }

View File

@ -1,11 +1,12 @@
import type { MetaObject } from '@/api/ius/types'; import type { MetaObject } from '@/api/ius/types';
import { Checkbox, Input, InputNumber } from 'ui'; import { Checkbox, Input, InputNumber, Textarea } from '@repo/ui';
function wrapMap<C, T extends Record<MetaObject['fieldType'], C>>(arg: T) { function wrapMap<C, T extends Record<MetaObject['fieldType'], C>>(arg: T) {
return arg; return arg;
} }
export const mapFieldTypeElement = wrapMap({ export const mapFieldTypeElement = wrapMap({
BIGSTRING: Textarea,
CHECKBOX: Checkbox, CHECKBOX: Checkbox,
DECIMAL: InputNumber, DECIMAL: InputNumber,
INT: InputNumber, INT: InputNumber,

View File

@ -1,5 +1,6 @@
const envSchema = require('./schema/env.js'); const { clientEnvSchema, serverEnvSchema } = require('./schema/env');
const getEnv = () => envSchema.parse(process.env); const getClientEnv = () => clientEnvSchema.parse(process.env);
const getServerEnv = () => serverEnvSchema.parse(process.env);
module.exports = { getEnv }; module.exports = { getClientEnv, getServerEnv };

View File

@ -2,7 +2,15 @@ const { z } = require('zod');
const envSchema = z.object({ const envSchema = z.object({
URL_IUS_DIRECT: z.string(), URL_IUS_DIRECT: z.string(),
USE_DEV_COLORS: z.string().optional(), NEXT_PUBLIC_USE_DEV_COLORS: z.string().optional(),
}); });
module.exports = envSchema; const serverEnvSchema = envSchema.pick({
URL_IUS_DIRECT: true,
});
const clientEnvSchema = envSchema.pick({
NEXT_PUBLIC_USE_DEV_COLORS: true,
});
module.exports = { envSchema, serverEnvSchema, clientEnvSchema };

View File

@ -1,9 +1,18 @@
import { getEnv } from './env'; import { getServerEnv } from './env';
import proxyUrls from '@/constants/urls';
const { URL_IUS_DIRECT } = getEnv(); import { isServer } from '@/utils/common';
export function getUrls() { export function getUrls() {
if (isServer()) {
const env = getServerEnv();
const { URL_IUS_DIRECT } = env;
return {
URL_IUS: URL_IUS_DIRECT,
};
}
return { return {
URL_UIS: URL_IUS_DIRECT, URL_IUS: proxyUrls.URL_IUS_PROXY,
}; };
} }

View File

@ -1,4 +1,4 @@
import { getEnv } from '../config/env'; import { getClientEnv } from '../config/env';
export const COLORS_PROD = { export const COLORS_PROD = {
COLOR_DANGER: '#B20004', COLOR_DANGER: '#B20004',
@ -12,5 +12,5 @@ export const COLORS_DEV = {
COLOR_SECONDARY: '#c54a84', COLOR_SECONDARY: '#c54a84',
COLOR_TERTIARTY: '#FF9112', COLOR_TERTIARTY: '#FF9112',
}; };
const env = getEnv(); const env = getClientEnv();
export const COLORS = env.USE_DEV_COLORS ? COLORS_DEV : COLORS_PROD; export const COLORS = env.NEXT_PUBLIC_USE_DEV_COLORS ? COLORS_DEV : COLORS_PROD;

View File

@ -0,0 +1,3 @@
module.exports = {
URL_IUS_PROXY: '/api/ius',
};

View File

@ -1,11 +1,12 @@
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const envSchema = require('./config/schema/env'); const { envSchema } = require('./config/schema/env');
const urls = require('./constants/urls');
const env = envSchema.parse(process.env); const env = envSchema.parse(process.env);
const favicons = fs.readdirSync('./public/favicon/prod'); const favicons = fs.readdirSync('./public/favicon/prod');
const faviconSubPath = env.USE_DEV_COLORS ? '/favicon/dev' : '/favicon/prod'; const faviconSubPath = env.NEXT_PUBLIC_USE_DEV_COLORS ? '/favicon/dev' : '/favicon/prod';
function buildFaviconRewrite(source) { function buildFaviconRewrite(source) {
return { return {
destination: String.prototype.concat(faviconSubPath, source), destination: String.prototype.concat(faviconSubPath, source),
@ -23,10 +24,17 @@ const nextConfig = {
outputFileTracingRoot: path.join(__dirname, '../../'), outputFileTracingRoot: path.join(__dirname, '../../'),
}, },
reactStrictMode: true, reactStrictMode: true,
transpilePackages: ['ui'], transpilePackages: ['@repo/ui', 'radash'],
async rewrites() { async rewrites() {
return [...favicons.map((fileName) => buildFaviconRewrite(`/${fileName}`))]; return [
{
destination: env.URL_IUS_DIRECT + '/:path*',
source: urls.URL_IUS_PROXY + '/:path*',
},
...favicons.map((fileName) => buildFaviconRewrite(`/${fileName}`)),
];
}, },
env,
}; };
module.exports = nextConfig; module.exports = nextConfig;

View File

@ -10,20 +10,21 @@
}, },
"dependencies": { "dependencies": {
"@heroicons/react": "^2.0.18", "@heroicons/react": "^2.0.18",
"next": "^14.0.1", "@repo/tsconfig": "workspace:*",
"@repo/ui": "workspace:*",
"next": "^14.1.0",
"radash": "^11.0.0",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"tsconfig": "*",
"ui": "*",
"wretch": "^2.7.0", "wretch": "^2.7.0",
"zod": "^3.22.4", "zod": "^3.22.4",
"zustand": "^4.4.6" "zustand": "^4.5.0"
}, },
"devDependencies": { "devDependencies": {
"@tailwindcss/forms": "^0.5.6", "@tailwindcss/forms": "^0.5.6",
"@types/node": "^20.9.0", "@types/node": "^20.10.0",
"@types/react": "^18.2.37", "@types/react": "^18.2.39",
"@types/react-dom": "^18.2.15", "@types/react-dom": "^18.2.17",
"@vchikalkin/eslint-config-awesome": "^1.1.5", "@vchikalkin/eslint-config-awesome": "^1.1.5",
"autoprefixer": "^10.4.16", "autoprefixer": "^10.4.16",
"eslint": "^8.53.0", "eslint": "^8.53.0",

View File

@ -0,0 +1,21 @@
{
"background_color": "#fff",
"description": "External | Эволюция",
"display": "standalone",
"icons": [
{
"sizes": "192x192",
"src": "/android-chrome-192x192.png",
"type": "image/png"
},
{
"sizes": "512x512",
"src": "/android-chrome-512x512.png",
"type": "image/png"
}
],
"name": "External | Эволюция",
"short_name": "External | Эволюция",
"start_url": "/",
"theme_color": "#fff"
}

View File

@ -12,8 +12,10 @@ type FormState = {
defaultValues: Values; defaultValues: Values;
init: (values: Values) => void; init: (values: Values) => void;
reset: () => void; reset: () => void;
resetValidation: () => void;
setValidation: (input: { name: string } & ElementValidation) => void; setValidation: (input: { name: string } & ElementValidation) => void;
setValue: ({ name, value }: { name: string; value: Values[number] }) => void; setValue: ({ name, value }: { name: string; value: Values[number] }) => void;
status?: 'init' | 'edited';
validation: Record<string, ElementValidation | undefined>; validation: Record<string, ElementValidation | undefined>;
values: Values; values: Values;
}; };
@ -23,24 +25,29 @@ export const useFormStore = create<FormState>((set) => ({
init: (values) => init: (values) =>
set(() => ({ set(() => ({
defaultValues: values, defaultValues: values,
status: 'init',
values, values,
})), })),
reset: () => { reset: () =>
set((state) => ({ set((state) => ({
status: 'init',
validation: {}, validation: {},
values: state.defaultValues, values: state.defaultValues,
})); })),
}, resetValidation: () =>
setValidation: ({ message, name, valid }) => { set(() => ({
validation: {},
})),
setValidation: ({ message, name, valid }) =>
set((state) => ({ set((state) => ({
validation: { validation: {
...state.validation, ...state.validation,
[name]: { message, valid }, [name]: { message, valid },
}, },
})); })),
},
setValue: ({ name, value }) => setValue: ({ name, value }) =>
set((state) => ({ set((state) => ({
status: 'edited',
validation: { validation: {
...state.validation, ...state.validation,
[name]: undefined, [name]: undefined,

View File

@ -1,5 +1,5 @@
{ {
"extends": "tsconfig/nextjs.json", "extends": "@repo/tsconfig/nextjs.json",
"compilerOptions": { "compilerOptions": {
"plugins": [{ "name": "next" }], "plugins": [{ "name": "next" }],
"paths": { "paths": {

View File

@ -1,4 +1,4 @@
export type PageProps = { export type PageProps = {
params: { slug: string }; params: { slug: string };
searchParams: string | string[][] | Record<string, string>; searchParams: Record<string, string>;
}; };

View File

@ -1,5 +1,5 @@
import type * as t from '@/api/ius/types'; import type * as t from '@/api/ius/types';
import { HttpError } from 'ui'; import { HttpError } from '@repo/ui';
import type { WretchError } from 'wretch/types'; import type { WretchError } from 'wretch/types';
type Props = { type Props = {

View File

@ -1,7 +1,7 @@
import type { PageProps } from '@/types/page'; import type { PageProps } from '@/types/page';
export function getPageUrlParams({ params, searchParams }: PageProps) { export function getPageUrlParams({ params, searchParams }: PageProps) {
return { path: `/${params.slug}`, urlSearchParams: new URLSearchParams(searchParams) }; return { path: `/${params.slug}`, urlSearchParams: searchParams };
} }
export type PageUrlParams = ReturnType<typeof getPageUrlParams>; export type PageUrlParams = ReturnType<typeof getPageUrlParams>;

20
docker-compose.yml Normal file
View File

@ -0,0 +1,20 @@
version: '3.3'
services:
external_client:
environment:
- URL_IUS_DIRECT=${URL_IUS_DIRECT}
- NEXT_PUBLIC_USE_DEV_COLORS=${NEXT_PUBLIC_USE_DEV_COLORS}
build:
args:
- URL_IUS_DIRECT=${URL_IUS_DIRECT}
- NEXT_PUBLIC_USE_DEV_COLORS=${NEXT_PUBLIC_USE_DEV_COLORS}
context: .
dockerfile: ./apps/web/Dockerfile
networks:
- external_network
restart: always
networks:
external_network:
external:
name: external_network

View File

@ -7,7 +7,7 @@
"lint:fix": "dotenv -e .env.local turbo run lint:fix", "lint:fix": "dotenv -e .env.local turbo run lint:fix",
"format": "prettier --write \"**/*.{ts,tsx,md}\"", "format": "prettier --write \"**/*.{ts,tsx,md}\"",
"prepare": "husky install", "prepare": "husky install",
"precommit": "yarn format && yarn lint:fix", "precommit": "pnpm format && pnpm lint:fix",
"clean": "turbo run clean" "clean": "turbo run clean"
}, },
"devDependencies": { "devDependencies": {
@ -17,15 +17,14 @@
"lint-staged": "^15.0.2", "lint-staged": "^15.0.2",
"prettier": "^3.0.3", "prettier": "^3.0.3",
"prettier-plugin-tailwindcss": "^0.5.6", "prettier-plugin-tailwindcss": "^0.5.6",
"tsconfig": "*", "@repo/tsconfig": "workspace:*",
"turbo": "latest" "turbo": "latest"
}, },
"name": "Evo.External.App", "name": "Evo.External.App",
"packageManager": "yarn@1.22.19", "packageManager": "pnpm@8.9.0",
"workspaces": [ "engines": {
"apps/*", "node": ">=18"
"packages/*" },
],
"lint-staged": { "lint-staged": {
"*.{js,jsx,ts,tsx}": [ "*.{js,jsx,ts,tsx}": [
"eslint --ignore-pattern **/graphql/* --ext js,jsx,ts,tsx --quiet --fix --" "eslint --ignore-pattern **/graphql/* --ext js,jsx,ts,tsx --quiet --fix --"

View File

@ -2,20 +2,19 @@
"$schema": "https://json.schemastore.org/tsconfig", "$schema": "https://json.schemastore.org/tsconfig",
"display": "Default", "display": "Default",
"compilerOptions": { "compilerOptions": {
"composite": false,
"declaration": true, "declaration": true,
"declarationMap": true, "declarationMap": true,
"esModuleInterop": true, "esModuleInterop": true,
"forceConsistentCasingInFileNames": true, "incremental": false,
"inlineSources": false,
"isolatedModules": true, "isolatedModules": true,
"moduleResolution": "node", "lib": ["es2022", "DOM", "DOM.Iterable"],
"noUnusedLocals": false, "module": "NodeNext",
"noUnusedParameters": false, "moduleDetection": "force",
"preserveWatchOutput": true, "moduleResolution": "NodeNext",
"noUncheckedIndexedAccess": true,
"resolveJsonModule": true,
"skipLibCheck": true, "skipLibCheck": true,
"strict": true, "strict": true,
"strictNullChecks": true "target": "ES2022"
}, }
"exclude": ["node_modules"]
} }

View File

@ -4,18 +4,10 @@
"extends": "./base.json", "extends": "./base.json",
"compilerOptions": { "compilerOptions": {
"plugins": [{ "name": "next" }], "plugins": [{ "name": "next" }],
"module": "ESNext",
"moduleResolution": "Bundler",
"allowJs": true, "allowJs": true,
"declaration": false,
"declarationMap": false,
"incremental": true,
"jsx": "preserve", "jsx": "preserve",
"lib": ["dom", "dom.iterable", "esnext"], "noEmit": true
"module": "esnext", }
"noEmit": true,
"resolveJsonModule": true,
"strict": false,
"target": "es5"
},
"include": ["src", "next-env.d.ts"],
"exclude": ["node_modules"]
} }

View File

@ -1,5 +1,5 @@
{ {
"name": "tsconfig", "name": "@repo/tsconfig",
"version": "0.0.0", "version": "0.0.0",
"private": true, "private": true,
"license": "MIT", "license": "MIT",

View File

@ -3,9 +3,6 @@
"display": "React Library", "display": "React Library",
"extends": "./base.json", "extends": "./base.json",
"compilerOptions": { "compilerOptions": {
"jsx": "react-jsx", "jsx": "react-jsx"
"lib": ["ES2015", "DOM"],
"module": "ESNext",
"target": "es6"
} }
} }

View File

@ -5,7 +5,7 @@ import type { ButtonHTMLAttributes } from 'react';
import { forwardRef } from 'react'; import { forwardRef } from 'react';
const variants = cva( const variants = cva(
'rounded-sm h-10 px-5 py-2.5 text-sm font-medium text-white transition-all ease-in-out', 'rounded-sm h-10 px-5 py-2.5 text-sm font-semibold text-white transition-all ease-in-out',
{ {
defaultVariants: { defaultVariants: {
intent: 'default', intent: 'default',
@ -13,14 +13,16 @@ const variants = cva(
variants: { variants: {
intent: { intent: {
danger: 'bg-danger hover:bg-danger-700', danger: 'bg-danger hover:bg-danger-700',
default: 'bg-primary hover:bg-primary-700', default: 'bg-primary hover:bg-primary-600',
'outline-danger': 'outline-danger':
'bg-transparent text-danger border border-danger hover:bg-danger hover:text-white', 'bg-transparent text-danger border border-danger hover:bg-danger hover:text-white',
'outline-default': 'outline-default':
'bg-transparent text-primary border border-primary hover:bg-primary hover:text-white', 'bg-transparent text-primary border border-primary hover:bg-primary hover:text-white',
'outline-secondary': 'outline-secondary':
'opacity-70 bg-transparent text-secondary border border-secondary hover:bg-secondary hover:text-white', 'border border-primary text-primary-500 hover:bg-primary-500 hover:text-white',
secondary: 'bg-secondary hover:bg-secondary-700', secondary:
'bg-primary-50 text-primary-500 border border-transparent hover:bg-primary-100 hover:text-primary-600',
text: 'bg-none text-primary-500 hover:bg-primary-50',
}, },
}, },
} }

View File

@ -5,7 +5,7 @@ import { forwardRef, type HTMLAttributes, type PropsWithChildren } from 'react';
export type ContainerProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren; export type ContainerProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren;
const variants = cva('flex h-9 items-center', { const variants = cva('flex min-h-[36px] items-center', {
defaultVariants: { defaultVariants: {
intent: 'default', intent: 'default',
}, },

View File

@ -1,5 +1,9 @@
import type { PropsWithChildren } from 'react'; import type { PropsWithChildren } from 'react';
export function Content({ children }: PropsWithChildren) { export function Content({ children }: PropsWithChildren) {
return <div className="flex w-full justify-center gap-2 py-5">{children}</div>; return (
<div className="grid w-full place-items-center">
<div className="xl:w-standard grid w-screen gap-5">{children}</div>
</div>
);
} }

View File

@ -6,7 +6,7 @@ import { forwardRef } from 'react';
const variants = cva('font-bold leading-7 text-gray-900 sm:truncate sm:tracking-tight', { const variants = cva('font-bold leading-7 text-gray-900 sm:truncate sm:tracking-tight', {
defaultVariants: { defaultVariants: {
size: 'default', size: 1,
}, },
variants: { variants: {
size: { size: {
@ -19,7 +19,6 @@ const variants = cva('font-bold leading-7 text-gray-900 sm:truncate sm:tracking-
7: 'text-6xl sm:text-7xl', 7: 'text-6xl sm:text-7xl',
8: 'text-7xl sm:text-8xl', 8: 'text-7xl sm:text-8xl',
9: 'text-8xl sm:text-9xl', 9: 'text-8xl sm:text-9xl',
default: 'text-lg',
}, },
}, },
}); });

View File

@ -12,3 +12,4 @@ export * from './http-error';
export * from './icons'; export * from './icons';
export * from './input'; export * from './input';
export * from './select'; export * from './select';
export * from './textarea';

View File

@ -21,3 +21,15 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
export const InputNumber = forwardRef<HTMLInputElement, InputProps>((props, ref) => ( export const InputNumber = forwardRef<HTMLInputElement, InputProps>((props, ref) => (
<Input ref={ref} type="number" {...props} /> <Input ref={ref} type="number" {...props} />
)); ));
export const InputFile = forwardRef<HTMLInputElement, InputProps>((props, ref) => (
<input
{...props}
ref={ref}
type="file"
className="file:bg-primary-50 file:text-primary-500 hover:file:bg-primary-100 block w-full text-sm
text-slate-500 file:mr-4 file:rounded-sm file:border-0
file:px-4 file:py-2 file:text-sm file:font-semibold
hover:file:cursor-pointer disabled:cursor-not-allowed disabled:opacity-30 disabled:file:cursor-not-allowed"
/>
));

View File

@ -1,8 +1,6 @@
{ {
"name": "ui", "name": "@repo/ui",
"version": "0.0.0", "version": "0.0.0",
"main": "./index.tsx",
"types": "./index.tsx",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"lint": "eslint .", "lint": "eslint .",
@ -10,15 +8,15 @@
}, },
"devDependencies": { "devDependencies": {
"@turbo/gen": "^1.10.16", "@turbo/gen": "^1.10.16",
"@types/node": "^20.8.10", "@types/node": "^20.10.0",
"@types/react": "^18.2.34", "@types/react": "^18.2.39",
"@types/react-dom": "^18.2.14", "@types/react-dom": "^18.2.17",
"@vchikalkin/eslint-config-awesome": "^1.1.5", "@vchikalkin/eslint-config-awesome": "^1.1.5",
"class-variance-authority": "^0.7.0", "class-variance-authority": "^0.7.0",
"clsx": "^2.0.0", "clsx": "^2.0.0",
"react": "^18.2.0", "react": "^18.2.0",
"tailwind-merge": "^2.0.0", "tailwind-merge": "^2.0.0",
"tsconfig": "*", "@repo/tsconfig": "workspace:*",
"typescript": "^5.2.2" "typescript": "^5.2.2"
} }
} }

19
packages/ui/textarea.tsx Normal file
View File

@ -0,0 +1,19 @@
import { cn } from './utils';
import type { VariantProps } from 'class-variance-authority';
import { cva } from 'class-variance-authority';
import { forwardRef } from 'react';
const variants = cva(
'focus:ring-0 min-h-[36px] resize-y h-auto hover:border-primary-500 focus:border-primary-500 w-full rounded-sm border disabled:hover:border-gray-300 border-gray-300 p-2 px-3 text-sm text-gray-900 outline-none transition-colors ease-in-out disabled:cursor-not-allowed disabled:text-opacity-30'
);
export type TextAreaProps = React.TextareaHTMLAttributes<HTMLTextAreaElement> &
VariantProps<typeof variants> & { readonly loading?: boolean };
export const Textarea = forwardRef<HTMLTextAreaElement, TextAreaProps>(
({ className, loading, ...props }, ref) => {
if (loading) return <div className="h-[98px] w-full animate-pulse rounded bg-gray-100" />;
return <textarea rows={4} ref={ref} className={cn(variants({ className }))} {...props} />;
}
);

View File

@ -1,5 +1,5 @@
{ {
"extends": "tsconfig/react-library.json", "extends": "@repo/tsconfig/react-library.json",
"include": ["."], "include": ["."],
"exclude": ["dist", "build", "node_modules"] "exclude": ["dist", "build", "node_modules"]
} }

7671
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

3
pnpm-workspace.yaml Normal file
View File

@ -0,0 +1,3 @@
packages:
- "apps/*"
- "packages/*"

View File

@ -1,3 +1,3 @@
{ {
"extends": "tsconfig/base.json" "extends": "@repo/tsconfig/base.json"
} }

5986
yarn.lock

File diff suppressed because it is too large Load Diff