Skip to content

Commit

Permalink
Merge pull request #2 from javiruiz27/new-structure
Browse files Browse the repository at this point in the history
feat: init new structure
  • Loading branch information
javiruiz27 authored Dec 17, 2024
2 parents 6cb6a22 + ed18d47 commit aeaedd2
Show file tree
Hide file tree
Showing 81 changed files with 4,288 additions and 816 deletions.
File renamed without changes.
16 changes: 16 additions & 0 deletions apps/login-ui/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>LoginUi</title>
<base href="/" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" href="/src/styles.css" />
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
9 changes: 9 additions & 0 deletions apps/login-ui/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "login-ui",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/login-ui/src",
"projectType": "application",
"tags": [],
"// targets": "to see all targets run: nx show project login-ui --web",
"targets": {}
}
File renamed without changes.
31 changes: 31 additions & 0 deletions apps/login-ui/src/app/AppStarter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import { ThemeProvider } from '@mui/material';
import { theme } from '@onboarding/themes';
import App from './App';
import { I18nProvider } from '@onboarding/i18n/feature';

const translations = {
//cant import of external file. eslint error
es: {
'test.test': 'prueba',
},
en: {
'test.test': 'test',
},
};

type Props = object;

const locale = navigator.language;

export const AppStarter: React.FC<Props> = () => {
const children = (
<ThemeProvider theme={theme}>
<I18nProvider translations={translations} locale={locale}>
<App />
</I18nProvider>
</ThemeProvider>
);

return children;
};
16 changes: 16 additions & 0 deletions apps/login-ui/src/app/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Typography } from '@mui/material';
import React from 'react';
import { FormattedMessage } from 'react-intl';

const App = () => {
return (
<div className="container">
<Typography variant="h1">HOLA QUE TAL</Typography>
<Typography variant="subtitle1">
<FormattedMessage id="test.test" />
</Typography>
</div>
);
};

export default App;
File renamed without changes.
16 changes: 16 additions & 0 deletions apps/login-ui/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { StrictMode } from 'react';
import { BrowserRouter } from 'react-router-dom';
import * as ReactDOM from 'react-dom/client';
import { AppStarter } from './app/AppStarter';

const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
);

root.render(
<StrictMode>
<BrowserRouter>
<AppStarter />
</BrowserRouter>
</StrictMode>
);
File renamed without changes.
9 changes: 9 additions & 0 deletions apps/login-ui/translations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"es": {
"test.test": "prueba"
},
"en": {
"test.test": "test"
}
}

27 changes: 27 additions & 0 deletions apps/login-ui/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": [
"node",
"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts",
"vite/client"
]
},
"exclude": [
"src/**/*.spec.ts",
"src/**/*.test.ts",
"src/**/*.spec.tsx",
"src/**/*.test.tsx",
"src/**/*.spec.js",
"src/**/*.test.js",
"src/**/*.spec.jsx",
"src/**/*.test.jsx",
"vite.config.ts",
"vite.config.mts",
"vitest.config.ts",
"vitest.config.mts"
],
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
}
21 changes: 21 additions & 0 deletions apps/login-ui/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"jsx": "react-jsx",
"allowJs": false,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"types": ["vite/client", "vitest"]
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"extends": "../../tsconfig.base.json"
}
30 changes: 30 additions & 0 deletions apps/login-ui/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": [
"vitest/globals",
"vitest/importMeta",
"vite/client",
"node",
"vitest",
"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts"
]
},
"include": [
"vite.config.ts",
"vite.config.mts",
"vitest.config.ts",
"vitest.config.mts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/**/*.d.ts"
]
}
42 changes: 42 additions & 0 deletions apps/login-ui/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/// <reference types='vitest' />
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';

export default defineConfig({
root: __dirname,
cacheDir: '../../node_modules/.vite/apps/login-ui',
server: {
port: 4200,
host: 'localhost',
},
preview: {
port: 4300,
host: 'localhost',
},
plugins: [react(), nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])],
// Uncomment this if you are using workers.
// worker: {
// plugins: [ nxViteTsPaths() ],
// },
build: {
outDir: '../../dist/apps/login-ui',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
},
},
test: {
watch: false,
globals: true,
environment: 'jsdom',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
reporters: ['default'],
coverage: {
reportsDirectory: '../../coverage/apps/login-ui',
provider: 'v8',
},
},
});
12 changes: 12 additions & 0 deletions apps/otp/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const nx = require('@nx/eslint-plugin');
const baseConfig = require('../../eslint.config.js');

module.exports = [
...baseConfig,
...nx.configs['flat/react'],
{
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
// Override or add rules here
rules: {},
},
];
File renamed without changes.
2 changes: 1 addition & 1 deletion apps/ui/jest.config.ts → apps/otp/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export default {
'^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nx/react/babel'] }],
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/apps/ui',
coverageDirectory: '../../coverage/apps/otp',
};
6 changes: 3 additions & 3 deletions apps/ui/project.json → apps/otp/project.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "ui",
"name": "otp",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/ui/src",
"sourceRoot": "apps/otp/src",
"projectType": "application",
"tags": [],
"// targets": "to see all targets run: nx show project ui --web",
"// targets": "to see all targets run: nx show project otp --web",
"targets": {}
}
Binary file added apps/otp/public/favicon.ico
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import OtpInput from 'react-otp-input';
type OtpInputProps = {
userToken: string;
setUserToken: Dispatch<SetStateAction<string>>;
}

export const OtpInputComp: React.FC<OtpInputProps> = ({
userToken, setUserToken
}) =>{
};

export const OtpInputComp: React.FC<OtpInputProps> = ({
userToken,
setUserToken,
}) => {
return (
<OtpInput
value={userToken}
Expand All @@ -18,9 +18,9 @@ export const OtpInputComp: React.FC<OtpInputProps> = ({
renderSeparator={<span>-</span>}
renderInput={(props) => <input {...props} />}
inputStyle={{
height: "3em",
width: "3em"
height: '3em',
width: '3em',
}}
/>
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,30 @@ const RequestTokenForm: React.FC<IRequestTokenForm> = (props) => {
},
});

const { setIsWaitingForValidation, setEmail } = useContext(AuthenticationContext);
const {mutate: fetchNewToken, isSuccess, data} = useRequestToken();
const { setIsWaitingForValidation, setEmail } = useContext(
AuthenticationContext
);
const { mutate: fetchNewToken, isSuccess, data } = useRequestToken();

const onSubmit: SubmitHandler<Inputs> = (data, e) => {
e?.preventDefault();
fetchNewToken(data.emailRequired);
};

useEffect(() => {
if(data?.otp) {
if (data?.otp) {
setIsWaitingForValidation(true);
setEmail(data.emailRequired);
}
}, [isSuccess, data, setIsWaitingForValidation, setEmail])

}, [isSuccess, data, setIsWaitingForValidation, setEmail]);

return (
<form onSubmit={handleSubmit(onSubmit)}>
<FormControl>
<Typography variant="h5">Request a otp token</Typography>
<FormLabel>Email</FormLabel>
<TextField
size='small'
size="small"
{...register('emailRequired', {
required: true,
pattern: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Button, Typography } from '@mui/material';
import { useContext, useEffect, useState } from 'react';
import { OtpInputComp } from '../otp-input/otp-input';
import useValidateToken from '../../hooks/use-validate-token';
import { AuthenticationContext } from '../../context/authentication-context';
import { Snackbar } from '@mui/material';

const ValidateTokenForm = () => {
const [userToken, setUserToken] = useState<string>('');
const [openErrorMessage, setOpenErrorMessage] = useState<boolean>(false);

const {
mutate: fetchValidation,
isSuccess,
data: jwtToken,
error,
} = useValidateToken();
const { email } = useContext(AuthenticationContext);

const handleValidateToken = () => {
fetchValidation({ email: email ?? '', otp: userToken });
};

useEffect(() => {
if (error) {
setOpenErrorMessage(true);
}
}, [error]);

return (
<div
style={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
gap: '8px',
}}
>
<Typography variant="h5">Introduce your token</Typography>
<OtpInputComp userToken={userToken} setUserToken={setUserToken} />
<Button type="submit" onClick={handleValidateToken}>
Validate
</Button>
<Snackbar
open={openErrorMessage}
message={'Error validating your otp token'}
onClose={() => setOpenErrorMessage(false)}
/>
</div>
);
};

export default ValidateTokenForm;
Loading

0 comments on commit aeaedd2

Please sign in to comment.