-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
290 additions
and
79 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
64 changes: 64 additions & 0 deletions
64
apps/frontend/src/lib/components/blocks/space/space-setting.svelte
This file contains 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,64 @@ | ||
<script lang="ts"> | ||
import { trpc } from "$lib/trpc/client" | ||
import { createMutation } from "@tanstack/svelte-query" | ||
import { updateSpaceCommand } from "@undb/commands" | ||
import { zodClient } from "sveltekit-superforms/adapters" | ||
import SuperDebug, { defaults, superForm } from "sveltekit-superforms" | ||
import { browser } from "$app/environment" | ||
import * as Form from "$lib/components/ui/form/index.js" | ||
import { Input } from "$lib/components/ui/input/index.js" | ||
import type { ISpaceDTO } from "@undb/space" | ||
import { toast } from "svelte-sonner" | ||
export let space: ISpaceDTO | ||
const form = superForm( | ||
defaults( | ||
{ | ||
name: space.name, | ||
}, | ||
zodClient(updateSpaceCommand), | ||
), | ||
{ | ||
SPA: true, | ||
dataType: "json", | ||
validators: zodClient(updateSpaceCommand), | ||
resetForm: false, | ||
invalidateAll: true, | ||
onUpdate(event) { | ||
if (!event.form.valid) { | ||
return | ||
} | ||
$updateSpaceMutation.mutate(event.form.data) | ||
}, | ||
}, | ||
) | ||
const updateSpaceMutation = createMutation({ | ||
mutationFn: trpc.space.update.mutate, | ||
onSuccess() { | ||
toast.success("Space updated successfully") | ||
}, | ||
}) | ||
const { form: formData, enhance } = form | ||
</script> | ||
|
||
<section class="mx-auto"> | ||
<form method="POST" class="w-2/3 space-y-4" use:enhance> | ||
<Form.Field {form} name="name"> | ||
<Form.Control let:attrs> | ||
<Form.Label>Space name</Form.Label> | ||
<Input {...attrs} placeholder="Set space display name..." bind:value={$formData.name} /> | ||
</Form.Control> | ||
<Form.Description>Change space display name.</Form.Description> | ||
<Form.FieldErrors /> | ||
</Form.Field> | ||
|
||
<Form.Button>Update</Form.Button> | ||
{#if browser} | ||
<!-- <SuperDebug data={$formData} /> --> | ||
{/if} | ||
</form> | ||
</section> |
This file contains 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ query GetIndexQuery { | |
id | ||
name | ||
isPersonal | ||
avatar | ||
} | ||
|
||
tables { | ||
|
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains 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,79 @@ | ||
<script lang="ts"> | ||
import * as Tabs from "$lib/components/ui/tabs" | ||
import InviteButton from "$lib/components/blocks/invite/invite-button.svelte" | ||
import MembersTable from "$lib/components/blocks/member/members-table.svelte" | ||
import { Input } from "$lib/components/ui/input" | ||
import { SettingsIcon, Users, UsersIcon } from "lucide-svelte" | ||
import type { LayoutData } from "./$types" | ||
import { queryParam } from "sveltekit-search-params" | ||
import InvitationsListButton from "$lib/components/blocks/invitations/invitations-list-button.svelte" | ||
import { hasPermission } from "$lib/store/workspace-member.store" | ||
import { onMount } from "svelte" | ||
import { goto } from "$app/navigation" | ||
import SpaceSetting from "$lib/components/blocks/space/space-setting.svelte" | ||
const mq = queryParam("mq") | ||
export let data: LayoutData | ||
$: getMembersStore = data.getMembersStore | ||
$: members = $getMembersStore.data?.members ?? [] | ||
function fetchMembers() { | ||
getMembersStore.fetch({ variables: { q: $mq } }) | ||
} | ||
$: store = data.indexDataStore | ||
$: space = $store.data?.space | ||
onMount(async () => { | ||
if ($store.data?.space?.isPersonal) { | ||
await goto("/", { replaceState: true }) | ||
} | ||
}) | ||
</script> | ||
|
||
<main class="space-y-2 p-6"> | ||
<div class="space-y-2"> | ||
<h3 class="flex items-center text-xl"> | ||
<SettingsIcon class="mr-2 h-4 w-4" /> | ||
Settings | ||
</h3> | ||
</div> | ||
|
||
<Tabs.Root value="members" class="w-full"> | ||
<Tabs.List> | ||
<Tabs.Trigger value="members"> | ||
<UsersIcon class="mr-2 h-4 w-4" /> | ||
Members | ||
</Tabs.Trigger> | ||
<Tabs.Trigger value="settings"> | ||
<SettingsIcon class="mr-2 h-4 w-4" /> | ||
Settings | ||
</Tabs.Trigger> | ||
</Tabs.List> | ||
<Tabs.Content value="members" class="space-y-2"> | ||
<div class="flex justify-between"> | ||
<h4 class="flex items-center"> | ||
<Users class="mr-2 h-4 w-4" /> | ||
Members | ||
</h4> | ||
<div class="flex items-center gap-2"> | ||
{#if $hasPermission("authz:invite")} | ||
<InviteButton /> | ||
{/if} | ||
{#if $hasPermission("authz:listInvitation")} | ||
<InvitationsListButton /> | ||
{/if} | ||
</div> | ||
</div> | ||
|
||
<Input bind:value={$mq} on:change={fetchMembers} placeholder="Search Members..." class="max-w-xs" /> | ||
<MembersTable {members} /> | ||
</Tabs.Content> | ||
<Tabs.Content value="settings"> | ||
{#if space} | ||
<SpaceSetting {space} /> | ||
{/if} | ||
</Tabs.Content> | ||
</Tabs.Root> | ||
</main> |
This file contains 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
28 changes: 28 additions & 0 deletions
28
packages/command-handlers/src/handlers/update-space.command-handler.ts
This file contains 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,28 @@ | ||
import { UpdateSpaceCommand } from "@undb/commands" | ||
import { mustGetCurrentSpaceId } from "@undb/context/server" | ||
import { commandHandler } from "@undb/cqrs" | ||
import { singleton } from "@undb/di" | ||
import { type ICommandHandler } from "@undb/domain" | ||
import { injectSpaceRepository, type ISpaceRepository } from "@undb/space" | ||
|
||
@commandHandler(UpdateSpaceCommand) | ||
@singleton() | ||
export class UpdateSpaceCommandHandler implements ICommandHandler<UpdateSpaceCommand, any> { | ||
constructor( | ||
@injectSpaceRepository() | ||
private readonly repository: ISpaceRepository, | ||
) {} | ||
|
||
async execute(command: UpdateSpaceCommand): Promise<any> { | ||
const spaceId = mustGetCurrentSpaceId() | ||
const space = (await this.repository.findOneById(spaceId)).expect("Space not found") | ||
|
||
const spec = space.$update(command) | ||
|
||
if (spec.isSome()) { | ||
await this.repository.updateOneById(space, spec.unwrap()) | ||
} | ||
|
||
return space.id.value | ||
} | ||
} |
This file contains 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 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,16 @@ | ||
import { Command, type CommandProps } from "@undb/domain" | ||
import { updateSpaceDTO } from "@undb/space" | ||
import { z } from "@undb/zod" | ||
|
||
export const updateSpaceCommand = updateSpaceDTO | ||
|
||
export type IUpdateSpaceCommand = z.infer<typeof updateSpaceCommand> | ||
|
||
export class UpdateSpaceCommand extends Command implements IUpdateSpaceCommand { | ||
public readonly name: string | ||
|
||
constructor(props: CommandProps<IUpdateSpaceCommand>) { | ||
super(props) | ||
this.name = props.name | ||
} | ||
} |
This file contains 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.