Skip to content

Commit 9e34853

Browse files
authored
Merge pull request #47 from Lemoncode/feature/edit-record-scene
Feature/edit record scene
2 parents c477ad0 + 2fc05ed commit 9e34853

File tree

19 files changed

+217
-7
lines changed

19 files changed

+217
-7
lines changed

src/common/components/sidebar-menu/item.sidebar-menu.component.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { Link as RouterLink } from '@tanstack/react-router';
2+
import { Link as RouterLink, useLocation } from '@tanstack/react-router';
33

44
import MuiLink from '@mui/material/Link';
55
import ListItem from '@mui/material/ListItem';
@@ -10,18 +10,18 @@ import ListItemText from '@mui/material/ListItemText';
1010
interface ItemProps {
1111
text: string;
1212
IconComponent?: React.ComponentType;
13-
// TODO: implement router links with safe types
1413
linkPath: string;
1514
}
1615

1716
export const Item: React.FC<ItemProps> = (props: ItemProps) => {
1817
const { text, IconComponent, linkPath } = props;
18+
const location = useLocation();
19+
const isSelected = location.pathname === linkPath;
1920

2021
return (
2122
<MuiLink component={RouterLink} to={linkPath} underline="none" color="textPrimary">
2223
<ListItem key={text}>
23-
{/* TODO: implement 'active path matching' using the router hook. "/users" path is used below just as an example */}
24-
<ListItemButton selected={linkPath === '/users'}>
24+
<ListItemButton selected={isSelected}>
2525
{IconComponent && <ListItemIcon>{<IconComponent />}</ListItemIcon>}
2626
<ListItemText primary={text} />
2727
</ListItemButton>

src/common/components/sidebar-menu/sidebar-menu.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const SidebarMenu: React.FC<Props> = props => {
2121
return (
2222
<List className={classes.list(theme, isDrawerOpen)}>
2323
<Item text="Principal" IconComponent={HomeIcon} linkPath={'/'} />
24-
<Item text="Expedientes" IconComponent={FolderIcon} linkPath={'/'} />
24+
<Item text="Expedientes" IconComponent={FolderIcon} linkPath={'/records'} />
2525
<Item text="Empresas" IconComponent={ApartmentIcon} linkPath={'/'} />
2626
<Item text="Informes" IconComponent={LeaderboardIcon} linkPath={'/'} />
2727
<Divider variant="middle" />

src/core/router/route-tree.ts

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ import { Route as LoginImport } from './../../scenes/login';
1515
import { Route as AuthImport } from './../../scenes/_auth';
1616
import { Route as IndexImport } from './../../scenes/index';
1717
import { Route as AuthUsersIndexImport } from './../../scenes/_auth/users/index';
18+
import { Route as AuthRecordsIndexImport } from './../../scenes/_auth/records/index';
1819
import { Route as AuthCreateUserIndexImport } from './../../scenes/_auth/create-user/index';
1920
import { Route as AuthUsersIdImport } from './../../scenes/_auth/users/$id';
2021
import { Route as AuthEditUserIdImport } from './../../scenes/_auth/edit-user/$id';
22+
import { Route as AuthEditRecordIdImport } from './../../scenes/_auth/edit-record/$id';
2123

2224
// Create/Update Routes
2325

@@ -44,6 +46,12 @@ const AuthUsersIndexRoute = AuthUsersIndexImport.update({
4446
getParentRoute: () => AuthRoute,
4547
} as any);
4648

49+
const AuthRecordsIndexRoute = AuthRecordsIndexImport.update({
50+
id: '/records/',
51+
path: '/records/',
52+
getParentRoute: () => AuthRoute,
53+
} as any);
54+
4755
const AuthCreateUserIndexRoute = AuthCreateUserIndexImport.update({
4856
id: '/create-user/',
4957
path: '/create-user/',
@@ -62,6 +70,12 @@ const AuthEditUserIdRoute = AuthEditUserIdImport.update({
6270
getParentRoute: () => AuthRoute,
6371
} as any);
6472

73+
const AuthEditRecordIdRoute = AuthEditRecordIdImport.update({
74+
id: '/edit-record/$id',
75+
path: '/edit-record/$id',
76+
getParentRoute: () => AuthRoute,
77+
} as any);
78+
6579
// Populate the FileRoutesByPath interface
6680

6781
declare module '@tanstack/react-router' {
@@ -87,6 +101,13 @@ declare module '@tanstack/react-router' {
87101
preLoaderRoute: typeof LoginImport;
88102
parentRoute: typeof rootRoute;
89103
};
104+
'/_auth/edit-record/$id': {
105+
id: '/_auth/edit-record/$id';
106+
path: '/edit-record/$id';
107+
fullPath: '/edit-record/$id';
108+
preLoaderRoute: typeof AuthEditRecordIdImport;
109+
parentRoute: typeof AuthImport;
110+
};
90111
'/_auth/edit-user/$id': {
91112
id: '/_auth/edit-user/$id';
92113
path: '/edit-user/$id';
@@ -108,6 +129,13 @@ declare module '@tanstack/react-router' {
108129
preLoaderRoute: typeof AuthCreateUserIndexImport;
109130
parentRoute: typeof AuthImport;
110131
};
132+
'/_auth/records/': {
133+
id: '/_auth/records/';
134+
path: '/records';
135+
fullPath: '/records';
136+
preLoaderRoute: typeof AuthRecordsIndexImport;
137+
parentRoute: typeof AuthImport;
138+
};
111139
'/_auth/users/': {
112140
id: '/_auth/users/';
113141
path: '/users';
@@ -121,16 +149,20 @@ declare module '@tanstack/react-router' {
121149
// Create and export the route tree
122150

123151
interface AuthRouteChildren {
152+
AuthEditRecordIdRoute: typeof AuthEditRecordIdRoute;
124153
AuthEditUserIdRoute: typeof AuthEditUserIdRoute;
125154
AuthUsersIdRoute: typeof AuthUsersIdRoute;
126155
AuthCreateUserIndexRoute: typeof AuthCreateUserIndexRoute;
156+
AuthRecordsIndexRoute: typeof AuthRecordsIndexRoute;
127157
AuthUsersIndexRoute: typeof AuthUsersIndexRoute;
128158
}
129159

130160
const AuthRouteChildren: AuthRouteChildren = {
161+
AuthEditRecordIdRoute: AuthEditRecordIdRoute,
131162
AuthEditUserIdRoute: AuthEditUserIdRoute,
132163
AuthUsersIdRoute: AuthUsersIdRoute,
133164
AuthCreateUserIndexRoute: AuthCreateUserIndexRoute,
165+
AuthRecordsIndexRoute: AuthRecordsIndexRoute,
134166
AuthUsersIndexRoute: AuthUsersIndexRoute,
135167
};
136168

@@ -140,19 +172,23 @@ export interface FileRoutesByFullPath {
140172
'/': typeof IndexRoute;
141173
'': typeof AuthRouteWithChildren;
142174
'/login': typeof LoginRoute;
175+
'/edit-record/$id': typeof AuthEditRecordIdRoute;
143176
'/edit-user/$id': typeof AuthEditUserIdRoute;
144177
'/users/$id': typeof AuthUsersIdRoute;
145178
'/create-user': typeof AuthCreateUserIndexRoute;
179+
'/records': typeof AuthRecordsIndexRoute;
146180
'/users': typeof AuthUsersIndexRoute;
147181
}
148182

149183
export interface FileRoutesByTo {
150184
'/': typeof IndexRoute;
151185
'': typeof AuthRouteWithChildren;
152186
'/login': typeof LoginRoute;
187+
'/edit-record/$id': typeof AuthEditRecordIdRoute;
153188
'/edit-user/$id': typeof AuthEditUserIdRoute;
154189
'/users/$id': typeof AuthUsersIdRoute;
155190
'/create-user': typeof AuthCreateUserIndexRoute;
191+
'/records': typeof AuthRecordsIndexRoute;
156192
'/users': typeof AuthUsersIndexRoute;
157193
}
158194

@@ -161,25 +197,47 @@ export interface FileRoutesById {
161197
'/': typeof IndexRoute;
162198
'/_auth': typeof AuthRouteWithChildren;
163199
'/login': typeof LoginRoute;
200+
'/_auth/edit-record/$id': typeof AuthEditRecordIdRoute;
164201
'/_auth/edit-user/$id': typeof AuthEditUserIdRoute;
165202
'/_auth/users/$id': typeof AuthUsersIdRoute;
166203
'/_auth/create-user/': typeof AuthCreateUserIndexRoute;
204+
'/_auth/records/': typeof AuthRecordsIndexRoute;
167205
'/_auth/users/': typeof AuthUsersIndexRoute;
168206
}
169207

170208
export interface FileRouteTypes {
171209
fileRoutesByFullPath: FileRoutesByFullPath;
172-
fullPaths: '/' | '' | '/login' | '/edit-user/$id' | '/users/$id' | '/create-user' | '/users';
210+
fullPaths:
211+
| '/'
212+
| ''
213+
| '/login'
214+
| '/edit-record/$id'
215+
| '/edit-user/$id'
216+
| '/users/$id'
217+
| '/create-user'
218+
| '/records'
219+
| '/users';
173220
fileRoutesByTo: FileRoutesByTo;
174-
to: '/' | '' | '/login' | '/edit-user/$id' | '/users/$id' | '/create-user' | '/users';
221+
to:
222+
| '/'
223+
| ''
224+
| '/login'
225+
| '/edit-record/$id'
226+
| '/edit-user/$id'
227+
| '/users/$id'
228+
| '/create-user'
229+
| '/records'
230+
| '/users';
175231
id:
176232
| '__root__'
177233
| '/'
178234
| '/_auth'
179235
| '/login'
236+
| '/_auth/edit-record/$id'
180237
| '/_auth/edit-user/$id'
181238
| '/_auth/users/$id'
182239
| '/_auth/create-user/'
240+
| '/_auth/records/'
183241
| '/_auth/users/';
184242
fileRoutesById: FileRoutesById;
185243
}
@@ -215,15 +273,21 @@ export const routeTree = rootRoute._addFileChildren(rootRouteChildren)._addFileT
215273
"/_auth": {
216274
"filePath": "_auth.tsx",
217275
"children": [
276+
"/_auth/edit-record/$id",
218277
"/_auth/edit-user/$id",
219278
"/_auth/users/$id",
220279
"/_auth/create-user/",
280+
"/_auth/records/",
221281
"/_auth/users/"
222282
]
223283
},
224284
"/login": {
225285
"filePath": "login.tsx"
226286
},
287+
"/_auth/edit-record/$id": {
288+
"filePath": "_auth/edit-record/$id.tsx",
289+
"parent": "/_auth"
290+
},
227291
"/_auth/edit-user/$id": {
228292
"filePath": "_auth/edit-user/$id.tsx",
229293
"parent": "/_auth"
@@ -236,6 +300,10 @@ export const routeTree = rootRoute._addFileChildren(rootRouteChildren)._addFileT
236300
"filePath": "_auth/create-user/index.tsx",
237301
"parent": "/_auth"
238302
},
303+
"/_auth/records/": {
304+
"filePath": "_auth/records/index.tsx",
305+
"parent": "/_auth"
306+
},
239307
"/_auth/users/": {
240308
"filePath": "_auth/users/index.tsx",
241309
"parent": "/_auth"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react';
2+
3+
export const EditCertificationsPod: React.FC = () => {
4+
return <h2>Certificaciones</h2>;
5+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './edit-certifications.pod';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react';
2+
3+
export const EditFinancialInformationPod: React.FC = () => {
4+
return <h2>Datos Económicos</h2>;
5+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './edit-financial-information.pod';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
3+
interface Props {
4+
id: string;
5+
}
6+
7+
export const EditGeneralInformationPod: React.FC<Props> = props => {
8+
const { id } = props;
9+
10+
return <h2>Datos Generales id: {id}</h2>;
11+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './edit-general-information.pod';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react';
2+
3+
export const EditNotesPod: React.FC = () => {
4+
return <h2>Notas</h2>;
5+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './edit.notes.pod';

src/modules/records/list/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './records.pod';
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import { NavigationButton } from '#common/components';
3+
4+
export const RecordsPod: React.FC = () => {
5+
return (
6+
<NavigationButton
7+
text="Editar expediente"
8+
path="/edit-record/$id"
9+
params={{
10+
id: '123456',
11+
}}
12+
/>
13+
);
14+
};

src/scenes/_auth/edit-record/$id.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { createFileRoute } from '@tanstack/react-router';
2+
import { EditRecordScene } from './edit-record.scene';
3+
4+
export const Route = createFileRoute('/_auth/edit-record/$id')({
5+
component: EditRecordScene,
6+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as React from 'react';
2+
import { useWithTheme } from '#core/theme';
3+
import * as innerClasses from './tab-panel.styles';
4+
5+
interface TabPanelProps {
6+
index: number;
7+
value: number;
8+
children: React.ReactNode;
9+
}
10+
11+
export const TabPanel = (props: TabPanelProps) => {
12+
const { children, value, index } = props;
13+
const classes = useWithTheme(innerClasses);
14+
15+
return value === index && <div className={classes.tabPanel}>{children}</div>;
16+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { css } from '@emotion/css';
2+
import { Theme } from '@mui/material';
3+
4+
export const tabPanel = (theme: Theme) => css`
5+
padding-block: ${theme.spacing(2)};
6+
`;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React from 'react';
2+
import { useParams } from '@tanstack/react-router';
3+
import { Tabs as MUITabs, Tab, Paper } from '@mui/material/';
4+
import { EditGeneralInformationPod } from '#modules/records/edit-general-information';
5+
import { EditFinancialInformationPod } from '#modules/records/edit-financial-information';
6+
import { EditCertificationsPod } from '#modules/records/edit-certifications';
7+
import { EditNotesPod } from '#modules/records/edit-notes';
8+
import { TabPanel } from './components/tab-panel.component';
9+
import * as innerClasses from './edit-record.styles';
10+
11+
enum TabIndex {
12+
GENERAL_INFORMATION,
13+
FINANCIAL_INFORMATION,
14+
CERTIFICATIONS,
15+
NOTES,
16+
}
17+
18+
export const EditRecordScene: React.FC = () => {
19+
const { id } = useParams({ from: '/_auth/edit-record/$id' });
20+
const [activeTab, setActiveTab] = React.useState<number>(0);
21+
22+
const handleChange = (_event: React.SyntheticEvent, newValue: number) => setActiveTab(newValue);
23+
24+
return (
25+
<div className={innerClasses.tabsComponent}>
26+
<Paper elevation={0}>
27+
<div className={innerClasses.tabsContainer}>
28+
<MUITabs value={activeTab} onChange={handleChange}>
29+
<Tab label="DATOS GENERALES" />
30+
<Tab label="DATOS ECONÓMICOS" />
31+
<Tab label="CERTIFICACIONES" />
32+
<Tab label="NOTAS" />
33+
</MUITabs>
34+
</div>
35+
<TabPanel value={activeTab} index={TabIndex.GENERAL_INFORMATION}>
36+
<EditGeneralInformationPod id={id} />
37+
</TabPanel>
38+
<TabPanel value={activeTab} index={TabIndex.FINANCIAL_INFORMATION}>
39+
<EditFinancialInformationPod />
40+
</TabPanel>
41+
<TabPanel value={activeTab} index={TabIndex.CERTIFICATIONS}>
42+
<EditCertificationsPod />
43+
</TabPanel>
44+
<TabPanel value={activeTab} index={TabIndex.NOTES}>
45+
<EditNotesPod />
46+
</TabPanel>
47+
</Paper>
48+
</div>
49+
);
50+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { css } from '@emotion/css';
2+
3+
export const tabsComponent = css`
4+
display: 'flex';
5+
flex-direction: 'column';
6+
align-items: 'center';
7+
width: 100%;
8+
`;
9+
10+
export const tabsContainer = css`
11+
border-bottom: 1;
12+
border-color: 'divider';
13+
`;

src/scenes/_auth/records/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { createFileRoute } from '@tanstack/react-router';
2+
import { RecordsPod } from '#modules/records/list';
3+
4+
export const Route = createFileRoute('/_auth/records/')({
5+
component: RecordsPod,
6+
});

0 commit comments

Comments
 (0)