Skip to content

Commit 24b33dc

Browse files
committed
tech(basic): update snippets directory
1 parent bb1b09f commit 24b33dc

File tree

18 files changed

+82
-81
lines changed

18 files changed

+82
-81
lines changed

recipes/basic/config.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const getConfig = () => {
22
return {
33
bundler: "webpack",
44
ui: "material-ui",
5-
state: "redux",
5+
state: "none",
66
buildDir: "public",
77
sourceDir: {
88
main: "src",
@@ -13,7 +13,7 @@ const getConfig = () => {
1313
i18n: "i18n",
1414
components: "components",
1515
businessLogic: "blocks",
16-
userInterface: "widgets",
16+
userInterface: "ui",
1717
utility: "utils",
1818
hooks: "hooks",
1919
theme: "theme",
@@ -24,11 +24,15 @@ const getConfig = () => {
2424
modules: {
2525
signIn: "SignIn",
2626
dashboard: "Dashboard",
27+
notFound: "NotFound",
2728
},
2829
canAdd: {
30+
gitIgnore: true,
2931
eslint: true,
32+
environment: true,
3033
prettier: true,
3134
husky: true,
35+
hooks: true,
3236
hookForm: true,
3337
routes: true,
3438
utils: true,
@@ -45,6 +49,7 @@ const getModulesList = () => {
4549
return [
4650
"reactWithI18n",
4751
"router",
52+
"services",
4853
"utils"
4954
];
5055
};

recipes/basic/snippets/sources/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { createBrowserHistory } from 'history'
66
import Routes from './Routes'
77
88
// Block Components.
9-
import { ErrorHandler, PageLoader } from '@${appName}/${sourceDir.businessLogic}'
9+
import { ErrorHandler, PageLoader } from '@/${sourceDir.businessLogic}'
1010
11-
import { withTranslation } from '@${appName}/${sourceDir.i18n}'
11+
import { withTranslation } from '@/${sourceDir.i18n}'
1212
1313
const browserHistory = createBrowserHistory()
1414

recipes/basic/snippets/sources/Dashboard.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
11
function getSourceCode(appName, { sourceDir }) {
2-
return `import React, { useState } from 'react'
3-
import { useHistory } from 'react-router-dom'
2+
return `import React from 'react'
3+
import { useNavigate } from 'react-router-dom'
44
import PropTypes from 'prop-types'
55
6-
import { I18nMsg } from '@${appName}/${sourceDir.i18n}'
6+
import { I18nMsg } from '@/${sourceDir.i18n}'
77
88
// Utils.
9-
import { RoutePaths } from '@${appName}/${sourceDir.utility}'
9+
import { RoutePaths } from '@/${sourceDir.utility}'
10+
11+
// Service Hooks
12+
import useFetch from '@/${sourceDir.hooks}/useFetch'
13+
14+
const SAMPLE_GET_API_URL = 'https://jsonplaceholder.typicode.com/users'
1015
1116
const Dashboard = (props) => {
12-
let history = useHistory()
17+
const navigate = useNavigate()
18+
19+
const { loading, error, response = [] } = useFetch(SAMPLE_GET_API_URL)
20+
21+
if (loading) return 'Loading..'
22+
if (error) return error.message
23+
1324
return (
1425
<>
1526
<section>
1627
<div>
1728
<h1>
1829
<I18nMsg id="dashboard" /> goes here
1930
</h1>
31+
{response.map((user) => {
32+
return <li key={user.id}>{user.name}</li>
33+
})}
2034
<button
2135
onClick={() => {
22-
history.push(RoutePaths.SignIn)
36+
navigate(RoutePaths.SignIn)
2337
}}
2438
>
2539
Click back

recipes/basic/snippets/sources/PageLoader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function getSourceCode(appName, { sourceDir }) {
22
return `import React, { Fragment } from 'react'
33
44
// UI Components.
5-
import { Spinner } from '@${appName}/${sourceDir.userInterface}'
5+
import { Spinner } from '@/${sourceDir.userInterface}'
66
77
export default function PageLoader({ loading }) {
88
// Add your business logic with store condition.

recipes/basic/snippets/sources/Routes.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
function getSourceCode(appName, { sourceDir, modules }) {
22
return `import React, { Suspense } from 'react'
3-
import { Route, Switch, Redirect } from 'react-router-dom'
3+
import { Route, Routes } from 'react-router-dom'
44
55
// Block Components.
6-
import { PageLoader } from '@${appName}/${sourceDir.businessLogic}'
6+
import { PageLoader } from '@/${sourceDir.businessLogic}'
77
88
// Utils.
9-
import { RoutePaths } from '@${appName}/${sourceDir.utility}'
9+
import { RoutePaths } from '@/${sourceDir.utility}'
1010
1111
const SignInModule = React.lazy(() =>
1212
import(/* webpackChunkName: "${sourceDir.containers}/${modules.signIn}" */ './${sourceDir.containers}/${modules.signIn}')
1313
)
14+
1415
const DashboardModule = React.lazy(() =>
1516
import(/* webpackChunkName: "${sourceDir.containers}/${modules.dashboard}" */ './${sourceDir.containers}/${modules.dashboard}')
1617
)
1718
18-
const Routes = () => {
19+
const NotFoundModule = React.lazy(() =>
20+
import(/* webpackChunkName: "${sourceDir.containers}/${modules.notFound}" */ './${sourceDir.containers}/${modules.notFound}')
21+
)
22+
23+
const RoutesComponent = () => {
1924
return (
2025
<Suspense fallback={<PageLoader />}>
21-
<Switch>
22-
<Route path={RoutePaths.SignIn} exact component={SignInModule} />
23-
<Route path={RoutePaths.Dashboard} component={DashboardModule} />
24-
<Redirect to={RoutePaths.NotFound} />
25-
</Switch>
26+
<Routes>
27+
<Route path={RoutePaths.SignIn} exact element={SignInModule} />
28+
<Route path={RoutePaths.Dashboard} element={DashboardModule} />
29+
<Route path="*" element={<NotFoundModule />} />
30+
</Routes>
2631
</Suspense>
2732
)
2833
}
2934
30-
export default Routes
35+
export default RoutesComponent
3136
`
3237
}
3338

recipes/basic/snippets/sources/Sidebar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
function getSourceCode(appName, { sourceDir }) {
22
return `import React from 'react'
33
import PropTypes from 'prop-types'
4-
import { useI18n } from '@${appName}/${sourceDir.i18n}'
4+
import { useI18n } from '@/${sourceDir.i18n}'
55
66
// Domain Components.
77
import SidebarNav from './SidebarNav'
88
99
// Utils.
10-
import { RoutePaths } from '@${appName}/${sourceDir.utility}'
10+
import { RoutePaths } from '@/${sourceDir.utility}'
1111
1212
const Sidebar = (props) => {
1313
const { open, variant, onClose, className, ...rest } = props

recipes/basic/snippets/sources/SignIn.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,57 @@
11
function getSourceCode(appName, { sourceDir }) {
22
return `import React from 'react'
3-
import { useHistory } from 'react-router-dom'
3+
import { useNavigate } from 'react-router-dom'
44
import PropTypes from 'prop-types'
55
66
// UI Components.
7-
import { InputTextField } from '@${appName}/${sourceDir.userInterface}'
7+
import { InputTextField } from '@/${sourceDir.userInterface}'
88
99
// Custom Hooks.
10-
import { useI18n } from '@${appName}/${sourceDir.i18n}'
10+
import { useI18n } from '@/${sourceDir.i18n}'
1111
1212
// Utils.
13-
import { RoutePaths } from '@${appName}/${sourceDir.utility}'
13+
import { RoutePaths } from '@/${sourceDir.utility}'
14+
15+
// Service Hooks
16+
import usePost from '@/${sourceDir.hooks}/usePost'
17+
18+
const SAMPLE_POST_API_URL = 'https://jsonplaceholder.typicode.com/posts'
1419
1520
const SignIn = (props) => {
16-
let history = useHistory()
21+
const navigate = useNavigate()
1722
const { formatMessage } = useI18n()
1823
24+
const { loading, error, response, sendPostData } = usePost(
25+
SAMPLE_POST_API_URL,
26+
'sendPostData'
27+
)
28+
1929
return (
2030
<>
2131
<section>
2232
<div>
2333
<h1>Login Form</h1>
34+
<div>
35+
{error && 'API is failed'}
36+
{response && 'Submitted successfully'}
37+
</div>
2438
Username:
2539
<InputTextField
2640
name="name"
2741
value=""
2842
placeholder={formatMessage({ id: 'user_name' })}
2943
/>
3044
<button
31-
onClick={() => {
32-
history.push(RoutePaths.DashBoard)
45+
onClick={async () => {
46+
await sendPostData({
47+
id: 1,
48+
title: 'title',
49+
body: 'body',
50+
userId: 1,
51+
})
52+
navigate(RoutePaths.DashBoard)
3353
}}
54+
disabled={loading}
3455
>
3556
go to dashboard
3657
</button>

recipes/basic/snippets/sources/TopBar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ return `import React from 'react'
33
import { Link as RouterLink } from 'react-router-dom'
44
import PropTypes from 'prop-types'
55
6-
import { I18nMsg } from '@${appName}/${sourceDir.i18n}'
6+
import { I18nMsg } from '@/${sourceDir.i18n}'
77
88
const TopBar = (props) => {
99
const { className, ...rest } = props

recipes/basic/snippets/sources/components/widgets/Fields/InputTextField/InputTextField.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

recipes/basic/snippets/sources/components/widgets/Fields/InputTextField/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)