From b1c18315ad16755f69e45b4edb52c7065ce43b81 Mon Sep 17 00:00:00 2001 From: hirsch Date: Sat, 7 Mar 2020 18:11:47 +0100 Subject: [PATCH] feat(home): add create tournament form --- package.json | 3 +- src/app/components/CreateTournamentForm.vue | 139 +++++++++++++- src/app/components/form/TextInput.vue | 153 +++++++++++++++ src/app/components/layout/Footer.vue | 4 +- src/app/components/layout/Header.vue | 24 ++- src/app/components/layout/Spinner.vue | 174 ++++++++++++++++++ ...formation.effect.ts => meta.api.effect.ts} | 0 src/app/effects/tournament.api.effect.ts | 46 +++++ src/app/pages/Home.vue | 33 ++-- src/i18n/en.ts | 77 ++++---- src/plugins/fontawesome.plugin.ts | 16 +- src/styles/styles.scss | 7 +- src/styles/utilities/_all.scss | 2 + src/styles/{ => utilities}/animations.scss | 37 ++++ src/styles/utilities/variables.scss | 72 ++++++++ src/styles/variables.scss | 30 --- src/types/vue.d.ts | 2 +- yarn.lock | 10 + 18 files changed, 723 insertions(+), 106 deletions(-) create mode 100644 src/app/components/form/TextInput.vue create mode 100644 src/app/components/layout/Spinner.vue rename src/app/effects/{api-information.effect.ts => meta.api.effect.ts} (100%) create mode 100644 src/app/effects/tournament.api.effect.ts create mode 100644 src/styles/utilities/_all.scss rename src/styles/{ => utilities}/animations.scss (99%) create mode 100644 src/styles/utilities/variables.scss delete mode 100644 src/styles/variables.scss diff --git a/package.json b/package.json index 5184cf5..da1a5e7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,6 @@ { "name": "copa-frontend", "version": "1.11.0", - "private": true, "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", @@ -15,6 +14,7 @@ "@fortawesome/free-solid-svg-icons": "^5.11.2", "@fortawesome/vue-fontawesome": "^0.1.7", "@types/qs": "^6.5.3", + "@types/validator": "^12.0.1", "@vue/composition-api": "^0.4.0", "axios": "^0.19.0", "buefy": "^0.8.5", @@ -26,6 +26,7 @@ "qs": "^6.9.0", "register-service-worker": "^1.6.2", "v-clipboard": "^2.2.2", + "validator": "^12.2.0", "vue": "^2.6.10", "vue-class-component": "^7.1.0", "vue-i18n": "^8.15.0", diff --git a/src/app/components/CreateTournamentForm.vue b/src/app/components/CreateTournamentForm.vue index 16a3516..d3d48ac 100644 --- a/src/app/components/CreateTournamentForm.vue +++ b/src/app/components/CreateTournamentForm.vue @@ -1,22 +1,147 @@ diff --git a/src/app/components/form/TextInput.vue b/src/app/components/form/TextInput.vue new file mode 100644 index 0000000..20f7aeb --- /dev/null +++ b/src/app/components/form/TextInput.vue @@ -0,0 +1,153 @@ + + + + + diff --git a/src/app/components/layout/Footer.vue b/src/app/components/layout/Footer.vue index 8e4831d..e9a769b 100644 --- a/src/app/components/layout/Footer.vue +++ b/src/app/components/layout/Footer.vue @@ -17,7 +17,7 @@ diff --git a/src/app/components/layout/Spinner.vue b/src/app/components/layout/Spinner.vue new file mode 100644 index 0000000..b967242 --- /dev/null +++ b/src/app/components/layout/Spinner.vue @@ -0,0 +1,174 @@ + + + + + diff --git a/src/app/effects/api-information.effect.ts b/src/app/effects/meta.api.effect.ts similarity index 100% rename from src/app/effects/api-information.effect.ts rename to src/app/effects/meta.api.effect.ts diff --git a/src/app/effects/tournament.api.effect.ts b/src/app/effects/tournament.api.effect.ts new file mode 100644 index 0000000..6b2938d --- /dev/null +++ b/src/app/effects/tournament.api.effect.ts @@ -0,0 +1,46 @@ +import Vue from 'vue' +import {computed, ref} from '@vue/composition-api' +import {classToPlain, plainToClass} from 'class-transformer' +import {defaultApiConfig} from '@/config/api.config' +import {Tournament} from '@/app/models/Tournament' +import {CreateTournamentRequest} from '@/app/models/CreateTournamentRequest' +import {AxiosError, AxiosRequestConfig} from 'axios' + +const apiTournamentConfig: AxiosRequestConfig = { + ...defaultApiConfig, + url: 'tournament', +} + +export const useApiTournamentCreate = () => { + const isPending = ref(false) + const error = ref>(null) + const createdTournament = ref({}) + + const createTournament = async (createTournamentRequest: CreateTournamentRequest) => { + isPending.value = true + error.value = null + const data = classToPlain(createTournamentRequest) + try { + const response = await Vue.$http.request({ + ...apiTournamentConfig, + method: 'POST', + data, + }) + createdTournament.value = plainToClass(Tournament, response.data) + } catch (exception) { + error.value = exception + } + + isPending.value = false + return createdTournament + } + + return { + isPending, + createdTournament, + hasError: computed(() => !!error.value), + createTournament, + } +} + + diff --git a/src/app/pages/Home.vue b/src/app/pages/Home.vue index fb55358..96469bc 100644 --- a/src/app/pages/Home.vue +++ b/src/app/pages/Home.vue @@ -4,22 +4,27 @@
-

+

- Create amazing
tournaments -

-

- Get started today for free
- A better way to manage your own tournament
- Invite your participants, generate your schedule and much more -

+ }"> +