diff --git a/src/api/models/ChallengeTemplateDTO.ts b/src/api/models/ChallengeTemplateDTO.ts index 323e64de48b8a201d3c4da78e5de83a904b0b0b1..286b0fc6fd32f7a9e313deceaf38f412f0e071ef 100644 --- a/src/api/models/ChallengeTemplateDTO.ts +++ b/src/api/models/ChallengeTemplateDTO.ts @@ -4,6 +4,7 @@ /* eslint-disable */ export type ChallengeTemplateDTO = { id?: number; + templateName?: string; text?: string; amount?: number; type?: ChallengeTemplateDTO.type; diff --git a/src/api/services/GoalService.ts b/src/api/services/GoalService.ts index b3bfa72d953cab2252919fc7ab21566db845e51f..bb0e011a19f29bf43f333704d9dbe22798a4645b 100644 --- a/src/api/services/GoalService.ts +++ b/src/api/services/GoalService.ts @@ -2,6 +2,7 @@ /* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { ChallengeDTO } from '../models/ChallengeDTO'; import type { CreateGoalDTO } from '../models/CreateGoalDTO'; import type { GoalDTO } from '../models/GoalDTO'; import type { MarkChallengeDTO } from '../models/MarkChallengeDTO'; @@ -78,6 +79,23 @@ export class GoalService { mediaType: 'application/json', }); } + /** + * @returns ChallengeDTO OK + * @throws ApiError + */ + public static regenerateChallenge({ + id, + }: { + id: number, + }): CancelablePromise<ChallengeDTO> { + return __request(OpenAPI, { + method: 'PATCH', + url: '/api/goals/challenge/{id}', + path: { + 'id': id, + }, + }); + } /** * @returns GoalDTO OK * @throws ApiError diff --git a/src/components/SavingGoal/SavingGoal.vue b/src/components/SavingGoal/SavingGoal.vue index 54cba56fcae6f3c3b0068aaa03a78fd9e06914a6..0ae8f52b788036ee227a3446f0d9050561e938f6 100644 --- a/src/components/SavingGoal/SavingGoal.vue +++ b/src/components/SavingGoal/SavingGoal.vue @@ -60,6 +60,15 @@ export default { this.savingGoalClicked = true; this.keyForList++ }, 100); + }, + async refreshSpareSti() { + try { + this.selectedGoal = await GoalService.getGoal({id: this.selectedGoal.id as number}) + console.log("yessir") + this.key++; + } catch (error) { + console.log(error) + } } }, }; @@ -82,7 +91,7 @@ export default { </div> </div> <saving-goal-create @createGoalClicked="handleCreateGoalClicked" v-if="createClicked"></saving-goal-create> - <saving-goal-roadmap :key="key" :selected-goal="selectedGoal" v-else-if="savingGoalClicked"></saving-goal-roadmap> + <saving-goal-roadmap @refreshSavingGoal="refreshSpareSti" :key="key" :selected-goal="selectedGoal" v-else-if="savingGoalClicked"></saving-goal-roadmap> <saving-goal-default v-else></saving-goal-default> </div> </div> diff --git a/src/components/SavingGoal/SavingGoalRoadmap.vue b/src/components/SavingGoal/SavingGoalRoadmap.vue index fe1a241977253da06dda6547cf78a0b8d0b27077..c88ba1a6c69f41b0da02c87f59e3cc62ab9e9331 100644 --- a/src/components/SavingGoal/SavingGoalRoadmap.vue +++ b/src/components/SavingGoal/SavingGoalRoadmap.vue @@ -10,7 +10,7 @@ import { UserService } from "@/api"; import {GoalService} from '@/api' -import {useUserInfoStore} from "@/stores/UserStore"; +import handleUnknownError from '@/components/Exceptions/unkownErrorHandler' ChartJS.register( CategoryScale, @@ -181,6 +181,7 @@ export default { await this.transferMoney(amount) this.calculateSavedSoFar(); } catch (error: any) { + handleUnknownError(error) console.log(error.message); } }, @@ -306,7 +307,9 @@ export default { }; try { await GoalService.updateChallengeAmount({requestBody: createGoalPayload}) + this.$emit('refreshSavingGoal'); } catch (e: any) { + handleUnknownError(e) console.log(e.message) } }, @@ -355,6 +358,17 @@ export default { await TransactionControllerService.transferToSelf({requestBody: transactionPayload}) }, + + async regenerateChallenge(challenge: ChallengeDTO) { + let challengeId = challenge.id as number + try { + let response = await GoalService.regenerateChallenge({id: challengeId}) + console.log(response) + this.$emit('refreshSavingGoal'); + } catch (e) { + handleUnknownError(e) + } + }, }, }; </script> @@ -383,8 +397,15 @@ export default { </div> <div class="timeline-panel z-3" :id="'panel-' + index" v-show="challenge.showPanel"> <div class="timeline-heading"> - <h5 style="margin-top: 12px">{{challenge.points}}<img src="../../assets/items/pigcoin.png" alt="pig coint" style="width: 2rem"></h5> - <h4>Utfordring {{ index +1 }}</h4> + <div class="coinAndRegen"> + <div class="coinCoin"> + <h5 style="margin-top: 12px">{{challenge.points}}<img src="../../assets/items/pigcoin.png" alt="pig coin" style="width: 2rem"></h5> + </div> + <div class="coinButton"> + <a @click="regenerateChallenge(challenge)" style="cursor: pointer"><img src="../../assets/icons/refresh.svg"/> Regenerer</a> + </div> + </div> + <h4>{{ challenge.challengeTemplate.templateName}}</h4> <p style="font-size: 12px">{{formatDate(challenge.startDate)}} til {{formatDate(challenge.endDate)}}</p> <h4 class="subheading">{{convertTemplateTextToChallengeText(challenge)}}</h4> </div> @@ -800,4 +821,28 @@ export default { margin-top: 10px; padding: 12px; } + +.timeline .coinAndRegen { + margin-top: 8px; + display: flex; + flex-direction: row-reverse; +} + +.timeline-inverted .coinAndRegen { + margin-top: 8px; + display: flex; + flex-direction: row; +} + +.coinCoin { + width: 40%; +} + +.coinButton { + width: 60%; + color: white; + align-content: center; + align-items: center; + text-align: center; +} </style> \ No newline at end of file