Skip to content

Commit 9015e3b

Browse files
author
Lasim
committed
refactor: enhance team creation flow with detailed success and error messages
1 parent d17d9c2 commit 9015e3b

4 files changed

Lines changed: 57 additions & 25 deletions

File tree

services/frontend/src/components/teams/AddTeamModal.vue

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface Props {
2222
2323
interface Emits {
2424
(e: 'update:open', value: boolean): void
25-
(e: 'teamCreated'): void
25+
(e: 'teamCreated', teamData: { name: string }): void
2626
}
2727
2828
const props = defineProps<Props>()
@@ -77,18 +77,19 @@ const handleSubmit = async () => {
7777
isSubmitting.value = true
7878
7979
try {
80+
const teamName = formData.value.name
8081
await TeamService.createTeam(formData.value)
8182
8283
// Emit global event for immediate UI updates across components
8384
eventBus.emit('teams-updated')
8485
85-
// Reset form
86+
// Close modal and emit success with team data
87+
isOpen.value = false
88+
emit('teamCreated', { name: teamName })
89+
90+
// Reset form after successful creation
8691
formData.value = { name: '', description: '' }
8792
errors.value = {}
88-
89-
// Close modal and emit success
90-
isOpen.value = false
91-
emit('teamCreated')
9293
} catch (error) {
9394
console.error('Error creating team:', error)
9495

services/frontend/src/i18n/locales/en/teams.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,15 @@ export default {
5050
create: 'Create Team',
5151
creating: 'Creating...'
5252
},
53+
messages: {
54+
createSuccess: 'Team "{teamName}" has been created successfully!',
55+
createSuccessGeneric: 'Team has been created successfully!'
56+
},
5357
errors: {
5458
limitReached: 'You have reached the maximum limit of 3 teams.',
5559
noPermission: 'You do not have permission to create teams.',
56-
unknown: 'An error occurred while creating the team.'
60+
unknown: 'An error occurred while creating the team.',
61+
refreshFailed: 'Team was created but failed to refresh the teams list. Please refresh the page.'
5762
}
5863
},
5964
manage: {

services/frontend/src/views/teams/TeamTableColumns.vue

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ const getRoleDisplay = (role: string) => {
127127
<TableCell>
128128
<div class="flex justify-end">
129129
<Button
130-
v-if="canManageTeam(team)"
131130
variant="outline"
132131
size="sm"
133132
class="h-8 px-3"
@@ -136,12 +135,6 @@ const getRoleDisplay = (role: string) => {
136135
<Settings class="h-4 w-4 mr-1" />
137136
{{ t('teams.table.manage') }}
138137
</Button>
139-
<span
140-
v-else
141-
class="text-muted-foreground text-sm"
142-
>
143-
{{ t('teams.table.noActions') }}
144-
</span>
145138
</div>
146139
</TableCell>
147140
</TableRow>

services/frontend/src/views/teams/index.vue

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { useEventBus } from '@/composables/useEventBus'
1212
import TeamTableColumns from './TeamTableColumns.vue'
1313
import { useRouter, useRoute } from 'vue-router'
1414
import { Alert, AlertDescription } from '@/components/ui/alert'
15-
import { CheckCircle } from 'lucide-vue-next'
15+
import { CheckCircle, AlertCircle } from 'lucide-vue-next'
1616
1717
const { t } = useI18n()
1818
const router = useRouter()
@@ -24,9 +24,10 @@ const teams = ref<TeamWithRole[]>([])
2424
const isLoading = ref(true)
2525
const error = ref<string | null>(null)
2626
const showAddModal = ref(false)
27-
const canCreateTeams = ref(false)
2827
const userPermissions = ref<string[]>([])
2928
const deleteSuccessMessage = ref<string | null>(null)
29+
const createSuccessMessage = ref<string | null>(null)
30+
const createErrorMessage = ref<string | null>(null)
3031
const searchQuery = ref('')
3132
3233
// Team switching state
@@ -66,12 +67,10 @@ const checkPermissions = async () => {
6667
try {
6768
const user = await UserService.getCurrentUser()
6869
if (user?.role?.permissions) {
69-
canCreateTeams.value = user.role.permissions.includes('teams.create')
7070
userPermissions.value = user.role.permissions
7171
}
7272
} catch (error) {
7373
console.error('Error checking permissions:', error)
74-
canCreateTeams.value = false
7574
userPermissions.value = []
7675
}
7776
}
@@ -94,7 +93,7 @@ const initializeSelectedTeam = async () => {
9493
const userTeams = await TeamService.getUserTeams()
9594
if (userTeams.length > 0) {
9695
const storedTeamId = eventBus.getState<string>('selected_team_id')
97-
96+
9897
if (storedTeamId) {
9998
// Try to find the stored team in available teams
10099
const storedTeam = userTeams.find(team => team.id === storedTeamId)
@@ -139,10 +138,33 @@ const fetchTeams = async (forceRefresh = false): Promise<void> => {
139138
}
140139
141140
// Handle team creation success
142-
const handleTeamCreated = async () => {
143-
await fetchTeams()
144-
// Emit global event to update sidebar and other components
145-
eventBus.emit('teams-updated')
141+
const handleTeamCreated = async (teamData?: { name: string }) => {
142+
// Clear any previous messages
143+
createSuccessMessage.value = null
144+
createErrorMessage.value = null
145+
146+
try {
147+
await fetchTeams()
148+
// Emit global event to update sidebar and other components
149+
eventBus.emit('teams-updated')
150+
151+
// Show success message
152+
if (teamData?.name) {
153+
createSuccessMessage.value = t('teams.addModal.messages.createSuccess', { teamName: teamData.name })
154+
} else {
155+
createSuccessMessage.value = t('teams.addModal.messages.createSuccessGeneric')
156+
}
157+
} catch (error) {
158+
console.error('Error refreshing teams after creation:', error)
159+
createErrorMessage.value = t('teams.addModal.errors.refreshFailed')
160+
}
161+
}
162+
163+
// Handle team creation error
164+
const handleTeamCreationError = (errorMessage: string) => {
165+
// Clear any previous messages
166+
createSuccessMessage.value = null
167+
createErrorMessage.value = errorMessage
146168
}
147169
148170
// Check for delete success message from query params
@@ -198,7 +220,6 @@ onUnmounted(() => {
198220
<p class="text-muted-foreground">{{ t('teams.description') }}</p>
199221
</div>
200222
<Button
201-
v-if="canCreateTeams"
202223
@click="showAddModal = true"
203224
class="flex items-center gap-2"
204225
>
@@ -207,12 +228,23 @@ onUnmounted(() => {
207228
</Button>
208229
</div>
209230

210-
<!-- Delete Success Message -->
231+
<!-- Success Messages -->
211232
<Alert v-if="deleteSuccessMessage" class="border-green-200 bg-green-50 text-green-800">
212233
<CheckCircle class="h-4 w-4" />
213234
<AlertDescription>{{ deleteSuccessMessage }}</AlertDescription>
214235
</Alert>
215236

237+
<Alert v-if="createSuccessMessage" class="border-green-200 bg-green-50 text-green-800">
238+
<CheckCircle class="h-4 w-4" />
239+
<AlertDescription>{{ createSuccessMessage }}</AlertDescription>
240+
</Alert>
241+
242+
<!-- Error Messages -->
243+
<Alert v-if="createErrorMessage" class="border-red-200 bg-red-50 text-red-800">
244+
<AlertCircle class="h-4 w-4" />
245+
<AlertDescription>{{ createErrorMessage }}</AlertDescription>
246+
</Alert>
247+
216248
<!-- Loading State -->
217249
<div v-if="isLoading" class="text-muted-foreground">
218250
{{ t('teams.table.loading') }}
@@ -248,6 +280,7 @@ onUnmounted(() => {
248280
<AddTeamModal
249281
v-model:open="showAddModal"
250282
@team-created="handleTeamCreated"
283+
@team-creation-error="handleTeamCreationError"
251284
/>
252285
</div>
253286
</DashboardLayout>

0 commit comments

Comments
 (0)