-
Notifications
You must be signed in to change notification settings - Fork 49
feat(dashboard): create a team from the switcher #372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
harshtandiya
wants to merge
1
commit into
version-2-dashboard-minor-sponsor-hide
Choose a base branch
from
version-2-dashboard-create-team-2
base: version-2-dashboard-minor-sponsor-hide
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <script setup lang="ts"> | ||
| import BuzzLogo from "@/components/common/BuzzLogo.vue"; | ||
|
|
||
| withDefaults(defineProps<{ text?: string }>(), { text: "Loading" }); | ||
| </script> | ||
|
|
||
| <template> | ||
| <div class="flex h-full min-h-64 flex-col items-center justify-center gap-4"> | ||
| <div class="relative"> | ||
| <!-- The copy behind carries the ping, so the logo itself stays readable. --> | ||
| <BuzzLogo | ||
| aria-hidden="true" | ||
| class="absolute inset-0 w-9 h-7 animate-ping text-ink-gray-3 motion-reduce:hidden" | ||
| /> | ||
| <BuzzLogo class="relative w-9 h-7 text-ink-gray-4" /> | ||
| </div> | ||
| <p class="text-sm text-ink-gray-5">{{ text }}</p> | ||
| </div> | ||
| </template> |
137 changes: 137 additions & 0 deletions
137
dashboard/src/components/dashboard/teams/CreateTeamDialog.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| <script setup lang="ts"> | ||
| import { createAndSelectTeam, createTeam } from "@/data/teams"; | ||
| import type { FrappeError } from "@/types"; | ||
| import { Avatar, Button, Dialog, ErrorMessage, FileUploader, toast } from "frappe-ui"; | ||
| import { computed, ref, watch } from "vue"; | ||
| import { useRouter } from "vue-router"; | ||
|
|
||
| const IMAGE_TYPES = ["image/png", "image/jpeg", "image/webp", "image/svg+xml"]; | ||
|
|
||
| const router = useRouter(); | ||
|
|
||
| const isOpen = defineModel<boolean>({ required: true }); | ||
|
|
||
| const teamName = ref(""); | ||
| const logo = ref(""); | ||
| const showErrors = ref(false); | ||
|
|
||
| // createResource types its error as {}, so the message needs narrowing. | ||
| const errorMessage = computed(() => (createTeam.error as FrappeError | null)?.message); | ||
|
|
||
| watch(isOpen, (open) => { | ||
| if (!open) return; | ||
| teamName.value = ""; | ||
| logo.value = ""; | ||
| showErrors.value = false; | ||
| createTeam.error = null; | ||
| }); | ||
|
|
||
| // The slug and the Owner membership come from the server, so a name is the whole form. | ||
| const invalid = computed(() => !teamName.value.trim()); | ||
|
|
||
| async function submit() { | ||
| showErrors.value = true; | ||
| if (invalid.value) return; | ||
|
|
||
| const team = await createAndSelectTeam({ | ||
| team_name: teamName.value.trim(), | ||
| logo: logo.value || null, | ||
| }); | ||
| if (!team) return; | ||
|
|
||
| toast.success(`${team.team_name} created`); | ||
| isOpen.value = false; | ||
| // The new team is already the selected one, so the overview opens on it. | ||
| router.push({ name: "team-overview" }); | ||
| } | ||
| </script> | ||
|
|
||
| <template> | ||
| <Dialog v-model="isOpen"> | ||
| <template #body-title> | ||
| <div class="flex items-center gap-2"> | ||
| <span class="lucide-users-round size-5 text-ink-gray-7" /> | ||
| <h3 class="text-2xl font-semibold text-ink-gray-9">Create team</h3> | ||
| </div> | ||
| </template> | ||
|
|
||
| <template #body-content> | ||
| <form novalidate class="flex flex-col items-center gap-4" @submit.prevent="submit"> | ||
| <FileUploader | ||
| :file-types="IMAGE_TYPES" | ||
| @success="(file: { file_url: string }) => (logo = file.file_url)" | ||
| > | ||
| <template #default="{ openFileSelector, uploading, error: uploadError }"> | ||
| <div class="flex flex-col items-center gap-1"> | ||
| <!-- The overlay is the control; the avatar under it is only the preview. --> | ||
| <button | ||
| type="button" | ||
| class="group relative rounded-xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-outline-gray-3" | ||
| :aria-label="logo ? 'Change logo' : 'Add logo'" | ||
| @click="openFileSelector" | ||
| > | ||
| <!-- Avatar sizes itself from the utility class rather than its size enum, | ||
| which tops out well below a preview worth looking at. --> | ||
| <Avatar | ||
| :image="logo || undefined" | ||
| shape="square" | ||
| class="size-24 rounded-xl" | ||
| /> | ||
| <!-- Empty, the icon is the whole placeholder; over an uploaded logo it | ||
| needs the backdrop to stay legible. --> | ||
| <span | ||
| class="absolute inset-0 grid place-items-center rounded-xl transition duration-150" | ||
| :class="[ | ||
| logo | ||
| ? 'bg-black/50 opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100' | ||
| : 'group-hover:bg-black/50', | ||
| uploading && 'opacity-100', | ||
| ]" | ||
| > | ||
| <span | ||
| class="size-6" | ||
| :class="[ | ||
| uploading | ||
| ? 'lucide-loader-circle animate-spin' | ||
| : 'lucide-camera', | ||
| logo | ||
| ? 'text-white' | ||
| : 'text-ink-gray-4 group-hover:text-white', | ||
| ]" | ||
| /> | ||
| </span> | ||
| </button> | ||
| <ErrorMessage v-if="uploadError" :message="String(uploadError)" /> | ||
| </div> | ||
| </template> | ||
| </FileUploader> | ||
|
|
||
| <!-- Unadorned on purpose: the name reads as the team's title, not as a form field. --> | ||
| <input | ||
| v-model="teamName" | ||
| aria-label="Team name" | ||
| placeholder="Team name" | ||
| autocomplete="off" | ||
| class="w-full bg-transparent text-center text-lg font-medium text-ink-gray-9 placeholder-ink-gray-4 focus:outline-none" | ||
| /> | ||
|
|
||
| <p v-if="showErrors && invalid" class="text-sm text-ink-red-4"> | ||
| A team needs a name. | ||
| </p> | ||
| <ErrorMessage v-else :message="errorMessage" /> | ||
|
|
||
| <!-- type=button: inside a form, a submit button would run `submit` twice — | ||
| once on click, once on the form's own submit — and the second insert | ||
| creates a second team. --> | ||
| <Button | ||
| type="button" | ||
| variant="solid" | ||
| label="Create" | ||
| class="w-full" | ||
| :loading="createTeam.loading" | ||
| @click="submit" | ||
| /> | ||
| </form> | ||
| </template> | ||
| </Dialog> | ||
| </template> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a user submits the form again while creation is in progress,
submitstarts another request because it does not guard oncreateTeam.loading, causing multiple teams to be persisted for one intended creation.Prompt To Fix With AI