Skip to content

Commit

Permalink
Merge pull request #442 from appwrite/feat-transfer-project-team
Browse files Browse the repository at this point in the history
Transfer Project to Another Team for appwrite 1.4.x
  • Loading branch information
TorstenDittmann authored Jul 19, 2023
2 parents 6fb40e1 + 43a0d8e commit 5c97d4e
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/lib/actions/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export enum Submit {
ProjectCreate = 'submit_project_create',
ProjectDelete = 'submit_project_delete',
ProjectUpdateName = 'submit_project_update_name',
ProjectUpdateTeam = 'submit_project_update_team',
ProjectService = 'submit_project_service',
MemberCreate = 'submit_member_create',
MemberDelete = 'submit_member_delete',
Expand Down
43 changes: 42 additions & 1 deletion src/routes/console/project-[project]/settings/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,37 @@
import { onMount } from 'svelte';
import { toLocaleDateTime } from '$lib/helpers/date';
import { addNotification } from '$lib/stores/notifications';
import { organizationList } from '$lib/stores/organization';
import { project } from '../store';
import { services, type Service } from '$lib/stores/project-services';
import { CardGrid, CopyInput, Box, Heading } from '$lib/components';
import { Button, Form, FormList, InputText, InputSwitch } from '$lib/elements/forms';
import {
Button,
Form,
FormList,
InputText,
InputSwitch,
InputSelect
} from '$lib/elements/forms';
import { Container } from '$lib/layout';
import { invalidate } from '$app/navigation';
import { Dependencies } from '$lib/constants';
import Delete from './deleteProject.svelte';
import { base } from '$app/paths';
import { page } from '$app/stores';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import Transfer from './transferProject.svelte';
let name: string = null;
let teamId: string = null;
let showDelete = false;
let showTransfer = false;
const endpoint = sdk.forConsole.client.config.endpoint;
const projectId = $page.params.project;
onMount(async () => {
name ??= $project.name;
teamId ??= $project.teamId;
});
async function updateName() {
Expand Down Expand Up @@ -137,7 +149,30 @@
</FormList>
</svelte:fragment>
</CardGrid>
<CardGrid>
<Heading tag="h6" size="7">Transfer project</Heading>
<p class="text">Transfer your project to another organization that you own.</p>

<svelte:fragment slot="aside">
<FormList>
<InputSelect
id="organization"
label="Available organizations"
bind:value={teamId}
options={$organizationList.teams.map((team) => ({
value: team.$id,
label: team.name
}))} />
</FormList>
</svelte:fragment>

<svelte:fragment slot="actions">
<Button
secondary
disabled={teamId === $project.teamId}
on:click={() => (showTransfer = true)}>Transfer</Button>
</svelte:fragment>
</CardGrid>
<CardGrid danger>
<div>
<Heading tag="h6" size="7">Delete Project</Heading>
Expand All @@ -163,3 +198,9 @@
</Container>

<Delete bind:showDelete />
{#if teamId}
<Transfer
bind:teamId
teamName={$organizationList.teams.find((t) => t.$id == teamId).name}
bind:show={showTransfer} />
{/if}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import { Modal } from '$lib/components';
import { Button } from '$lib/elements/forms';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { project } from '../store';
export let show = false;
export let teamName;
export let teamId;
const handleTransfer = async () => {
try {
await sdk.forConsole.client.call(
'PATCH',
new URL(
sdk.forConsole.client.config.endpoint + '/projects/' + $project.$id + '/team'
),
{
'content-type': 'application/json'
},
{
teamId: teamId
}
);
// await sdk.forConsole.projects.update($project.$id, password);
show = false;
addNotification({
type: 'success',
message: `${$project.name} has been transfered to ${teamName}`
});
trackEvent(Submit.ProjectUpdateTeam);
await goto(`${base}/console/organization-${teamId}`);
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.ProjectUpdateTeam);
}
};
</script>

<Modal bind:show onSubmit={handleTransfer} headerDivider={false}>
<svelte:fragment slot="header">Transfer project</svelte:fragment>
<p>Are you sure you want to transfer <b>{$project.name}</b> to <b>{teamName}</b>?</p>
<p>
Members who are not part of the destination organization must be invited to gain access to
this project.
</p>

<svelte:fragment slot="footer">
<Button text on:click={() => (show = false)}>Cancel</Button>
<Button secondary submit>Transfer</Button>
</svelte:fragment>
</Modal>

2 comments on commit 5c97d4e

@vercel
Copy link

@vercel vercel bot commented on 5c97d4e Jul 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

console-cloud – ./

console-cloud-appwrite.vercel.app
console-cloud-git-main-appwrite.vercel.app
console-cloud.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 5c97d4e Jul 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.