Skip to content

Commit 4f9e693

Browse files
✨(frontend) Create and init the next.js backoffice admin (#223)
* πŸŽ‰(frontend) add and init next js app for the back office Today, the creation and management of products is complicated and tedious. We therefore created a back office to facilitate this management and other aspects in Joanie such as invoicing * 🌐(frontend) add react-intl stack Added react-intl for app internationalization. * ✨(frontend) set up the test and mock stack Add and init jest and MSW (to mock API calls in tests + components) * πŸ”§(frontend) update circleci config Add tests, lints, etc from next.js stack in circleci * 🎨(frontend) run prettier-write the tests in the ci failed because prettier is broken
1 parent bfa07b0 commit 4f9e693

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+7120
-11
lines changed

β€Ž.DS_Storeβ€Ž

8 KB
Binary file not shown.

β€Ž.circleci/config.ymlβ€Ž

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,78 @@ jobs:
240240
- ./node_modules
241241
key: v1-mail-dependencies-{{ .Revision }}
242242

243+
# ---- frontend admin jobs ----
244+
build-front-admin:
245+
docker:
246+
- image: cimg/node:16.15
247+
auth:
248+
username: $DOCKER_HUB_USER
249+
password: $DOCKER_HUB_PASSWORD
250+
working_directory: ~/joanie/src/frontend/admin
251+
steps:
252+
- checkout:
253+
path: ~/joanie
254+
- restore_cache:
255+
keys:
256+
- v0-frontend-admin-dependencies-{{ checksum "~/joanie/src/frontend/admin/yarn.lock" }}
257+
- v0-frontend-admin-dependencies-
258+
- run:
259+
name: Install front-end dependencies
260+
command: yarn install
261+
- run:
262+
name: Build admin application
263+
command: yarn build
264+
- run:
265+
name: Use format-js cli to generate frontend.json file
266+
command: yarn i18n:extract
267+
- persist_to_workspace:
268+
root: ~/joanie
269+
paths:
270+
- src/frontend/admin/i18n/frontend.json
271+
- save_cache:
272+
paths:
273+
- ./node_modules
274+
key: v0-frontend-admin-dependencies-{{ checksum "yarn.lock" }}
275+
276+
lint-front-admin:
277+
docker:
278+
- image: cimg/node:16.15
279+
auth:
280+
username: $DOCKER_HUB_USER
281+
password: $DOCKER_HUB_PASSWORD
282+
working_directory: ~/joanie/src/frontend/admin
283+
steps:
284+
- checkout:
285+
path: ~/joanie
286+
- restore_cache:
287+
keys:
288+
- v0-frontend-admin-dependencies-{{ checksum "~/joanie/src/frontend/admin/yarn.lock" }}
289+
- v0-frontend-admin-dependencies-
290+
- run:
291+
name: Run lint command
292+
command: yarn lint
293+
294+
test-front-admin:
295+
docker:
296+
- image: cimg/node:16.15
297+
auth:
298+
username: $DOCKER_HUB_USER
299+
password: $DOCKER_HUB_PASSWORD
300+
working_directory: ~/joanie/src/frontend/admin
301+
steps:
302+
- checkout:
303+
path: ~/joanie
304+
- restore_cache:
305+
keys:
306+
- v0-frontend-admin-dependencies-{{ checksum "~/joanie/src/frontend/admin/yarn.lock" }}
307+
- v0-frontend-admin-dependencies-
308+
- run:
309+
name: Run test command
310+
command: yarn test
311+
243312

244313
# ---- Internationalization jobs ----
245-
build-i18n:
314+
build-back-i18n:
246315
docker:
247316
- image: cimg/python:3.10
248317
auth:
@@ -541,15 +610,35 @@ workflows:
541610
requires:
542611
- build-back
543612
- build-mails
544-
- build-i18n
613+
- build-back-i18n
614+
filters:
615+
tags:
616+
only: /.*/
617+
618+
# Frontend admin jobs
619+
#
620+
# Build, lint and test frontend admin application
621+
- build-front-admin:
622+
filters:
623+
tags:
624+
only: /.*/
625+
- lint-front-admin:
545626
filters:
546627
tags:
547628
only: /.*/
629+
requires:
630+
- build-front-admin
631+
- test-front-admin:
632+
filters:
633+
tags:
634+
only: /.*/
635+
requires:
636+
- build-front-admin
548637

549638
# Internationalization jobs
550639
#
551640
# Extract strings and upload them to our translation management platform
552-
- build-i18n:
641+
- build-back-i18n:
553642
requires:
554643
- build-back
555644
- build-mails
@@ -558,7 +647,8 @@ workflows:
558647
only: /.*/
559648
- upload-i18n-strings:
560649
requires:
561-
- build-i18n
650+
- build-back-i18n
651+
- build-front-admin
562652
filters:
563653
branches:
564654
only: main

β€Ž.gitignoreβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ share/python-wheels/
2626
.installed.cfg
2727
*.egg
2828
MANIFEST
29+
.idea
30+
.DS_Store
31+
*.iml
32+
.next/
2933

3034
# Translations # Translations
3135
*.pot

β€ŽMakefileβ€Ž

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ DOCKER_USER = $(DOCKER_UID):$(DOCKER_GID)
3636
COMPOSE = DOCKER_USER=$(DOCKER_USER) docker-compose
3737
COMPOSE_RUN = $(COMPOSE) run --rm
3838
COMPOSE_RUN_APP = $(COMPOSE_RUN) app-dev
39+
COMPOSE_RUN_FRONT_ADMIN = $(COMPOSE_RUN) app-dev-front-admin
3940
COMPOSE_RUN_CROWDIN = $(COMPOSE_RUN) crowdin crowdin
4041
COMPOSE_RUN_MAIL_YARN= $(COMPOSE_RUN) mail-generator yarn
4142
COMPOSE_TEST_RUN = $(COMPOSE_RUN)
@@ -67,7 +68,9 @@ bootstrap: \
6768
migrate \
6869
i18n-compile \
6970
install-mails \
70-
build-mails
71+
build-mails \
72+
front-admin-install \
73+
front-admin-build
7174
.PHONY: bootstrap
7275

7376
# -- Docker/compose
@@ -171,6 +174,14 @@ superuser: ## create a Django superuser
171174
@$(MANAGE) createsuperuser
172175
.PHONY: superuser
173176

177+
back-i18n-compile: ## compile the gettext files
178+
@$(MANAGE) compilemessages --ignore="venv/**/*"
179+
.PHONY: back-i18n-compile
180+
181+
back-i18n-generate: ## create the .pot files used for i18n
182+
@$(MANAGE) makemessages -a --keep-pot
183+
.PHONY: back-i18n-generate
184+
174185
shell: ## connect to database shell
175186
@$(MANAGE) shell_plus
176187
.PHONY: dbshell
@@ -181,6 +192,35 @@ dbshell: ## connect to database shell
181192
docker-compose exec app-dev python manage.py dbshell
182193
.PHONY: dbshell
183194

195+
# -- Frontend admin
196+
front-admin-install: ## Install node_modules
197+
@${COMPOSE_RUN_FRONT_ADMIN} yarn install
198+
.PHONY: front-admin-install
199+
200+
front-admin-lint: ## Lint frontend admin app
201+
@${COMPOSE_RUN_FRONT_ADMIN} yarn lint
202+
.PHONY: front-admin-lint
203+
204+
front-admin-test: ## Test frontend admin app
205+
@${COMPOSE_RUN_FRONT_ADMIN} yarn test
206+
.PHONY: front-admin-test
207+
208+
front-admin-build: ## Build frontend admin app
209+
@${COMPOSE_RUN_FRONT_ADMIN} yarn build
210+
.PHONY: front-admin-build
211+
212+
front-admin-dev: ## Launch frontend admin app in development mode
213+
@${COMPOSE_RUN_FRONT_ADMIN} yarn dev
214+
.PHONY: front-admin-dev
215+
216+
front-admin-i18n-extract: ## Extract translations of frontend admin app
217+
@${COMPOSE_RUN_FRONT_ADMIN} yarn i18n:extract
218+
.PHONY: front-admin-i18n-extract
219+
220+
front-admin-i18n-compile: ## Compile translations of frontend admin app
221+
@${COMPOSE_RUN_FRONT_ADMIN} yarn i18n:compile
222+
.PHONY: front-admin-i18n-compile
223+
184224
# -- Internationalization
185225

186226
env.d/development/crowdin:
@@ -194,20 +234,24 @@ crowdin-upload: ## Upload source translations to crowdin
194234
@$(COMPOSE_RUN_CROWDIN) upload sources -c crowdin/config.yml
195235
.PHONY: crowdin-upload
196236

197-
i18n-compile: ## compile the gettext files
198-
@$(MANAGE) compilemessages --ignore="venv/**/*"
237+
i18n-compile: ## compile all translations
238+
i18n-compile: \
239+
back-i18n-compile \
240+
front-admin-i18n-compile
199241
.PHONY: i18n-compile
200242

243+
i18n-generate: ## create the .pot files and extract frontend messages
244+
i18n-generate: \
245+
back-i18n-generate \
246+
front-admin-i18n-extract
247+
.PHONY: i18n-generate
248+
201249
i18n-download-and-compile: ## download all translated messages and compile them to be used by all applications
202250
i18n-download-and-compile: \
203251
crowdin-download \
204252
i18n-compile
205253
.PHONY: i18n-download-and-compile
206254

207-
i18n-generate: ## create the .pot files used for i18n
208-
@$(MANAGE) makemessages -a --keep-pot
209-
.PHONY: i18n-generate
210-
211255
i18n-generate-and-upload: ## generate source translations for all applications and upload them to crowdin
212256
i18n-generate-and-upload: \
213257
i18n-generate \

β€Žcrowdin/config.ymlβ€Ž

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ files: [
1919
source : "/backend/locale/django.pot",
2020
dest: "/backend.pot",
2121
translation : "/backend/locale/%locale_with_underscore%/LC_MESSAGES/django.po"
22+
},
23+
{
24+
source : "/frontend/admin/i18n/frontend.json",
25+
dest: "/admin/frontend.json",
26+
translation : "/frontend/admin/i18n/locales/%locale%.json"
2227
}
2328
]

β€Ždocker-compose.ymlβ€Ž

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ services:
8888
- ".:/app"
8989
working_dir: /app/src/mail
9090

91+
app-dev-front-admin:
92+
image: node:16.15
93+
user: ${DOCKER_USER:-1000}
94+
volumes:
95+
- "./src/frontend/admin:/app"
96+
working_dir: /app
97+
ports:
98+
- "8072:3000"
99+
depends_on:
100+
- app-dev
101+
91102
mailcatcher:
92103
image: sj26/mailcatcher:latest
93104
ports:

β€Žjoanie.imlβ€Ž

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="PYTHON_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="django" name="Django">
5+
<configuration>
6+
<option name="rootFolder" value="$MODULE_DIR$/src/backend/joanie/core" />
7+
<option name="settingsModule" value="settings.py" />
8+
<option name="manageScript" value="manage.py" />
9+
<option name="environment" value="&lt;map/&gt;" />
10+
<option name="doNotUseTestRunner" value="false" />
11+
<option name="trackFilePattern" value="migrations" />
12+
</configuration>
13+
</facet>
14+
</component>
15+
<component name="NewModuleRootManager" inherit-compiler-output="true">
16+
<exclude-output />
17+
<content url="file://$MODULE_DIR$">
18+
<excludeFolder url="file://$MODULE_DIR$/src/frontend/admin/.next" />
19+
</content>
20+
<orderEntry type="inheritedJdk" />
21+
<orderEntry type="sourceFolder" forTests="false" />
22+
</component>
23+
<component name="TemplatesService">
24+
<option name="TEMPLATE_CONFIGURATION" value="Django" />
25+
<option name="TEMPLATE_FOLDERS">
26+
<list>
27+
<option value="$MODULE_DIR$/src/backend/joanie/core/templates/mail/html" />
28+
<option value="$MODULE_DIR$/src/backend/joanie/core/templates/joanie/admin" />
29+
</list>
30+
</option>
31+
</component>
32+
</module>

β€Žsrc/.DS_Storeβ€Ž

6 KB
Binary file not shown.

β€Žsrc/backend/locale/es_ES/LC_MESSAGES/django.moβ€Ž

100644100755
File mode changed.

β€Žsrc/backend/locale/fr_CA/LC_MESSAGES/django.moβ€Ž

100644100755
File mode changed.

0 commit comments

Comments
Β (0)