2023-05-02 23:55:26 +00:00
|
|
|
<script>
|
2023-08-02 19:35:27 +01:00
|
|
|
import { goto } from '$app/navigation';
|
2023-05-02 23:55:26 +00:00
|
|
|
import { Grid, Row, Column } from 'carbon-components-svelte';
|
2023-08-02 19:35:27 +01:00
|
|
|
import TextField from '$lib/components/Form/TextField.svelte';
|
|
|
|
|
import PrimaryButton from '$lib/components/PrimaryButton/index.svelte';
|
|
|
|
|
import { VARIANTS } from '$lib/components/PrimaryButton/constants';
|
|
|
|
|
import UploadImage from '$lib/components/UploadImage/index.svelte';
|
|
|
|
|
import { supabase } from '$lib/utils/functions/supabase';
|
|
|
|
|
import { snackbarStore } from '$lib/components/Snackbar/store';
|
|
|
|
|
import { SNACKBAR_SEVERITY } from '$lib/components/Snackbar/constants';
|
|
|
|
|
import { currentOrg, currentOrgPath } from '$lib/utils/store/org';
|
2023-05-05 20:19:45 +00:00
|
|
|
import SectionTitle from '../SectionTitle.svelte';
|
2023-05-02 23:55:26 +00:00
|
|
|
|
|
|
|
|
let avatar;
|
|
|
|
|
let loading = false;
|
|
|
|
|
|
|
|
|
|
async function handleUpdate() {
|
|
|
|
|
try {
|
|
|
|
|
loading = true;
|
|
|
|
|
|
|
|
|
|
const updates = {
|
|
|
|
|
name: $currentOrg.name,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (avatar) {
|
|
|
|
|
const filename = `user/${$currentOrg.name + Date.now()}.webp`;
|
|
|
|
|
|
|
|
|
|
const { data } = await supabase.storage
|
|
|
|
|
.from('avatars')
|
|
|
|
|
.upload(filename, avatar, {
|
|
|
|
|
cacheControl: '3600',
|
|
|
|
|
upsert: false,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (data && data.Key) {
|
|
|
|
|
const { publicURL } = supabase.storage
|
|
|
|
|
.from('avatars')
|
|
|
|
|
.getPublicUrl(filename);
|
|
|
|
|
|
|
|
|
|
updates.avatar_url = publicURL;
|
|
|
|
|
$currentOrg.avatar_url = publicURL;
|
|
|
|
|
}
|
|
|
|
|
avatar = undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let { error } = await supabase
|
|
|
|
|
.from('organization')
|
2023-08-02 19:35:27 +01:00
|
|
|
.update(updates)
|
2023-05-02 23:55:26 +00:00
|
|
|
.match({ id: $currentOrg.id });
|
|
|
|
|
|
|
|
|
|
currentOrg.update((_currentOrg) => ({
|
|
|
|
|
..._currentOrg,
|
|
|
|
|
...updates,
|
|
|
|
|
}));
|
|
|
|
|
$snackbarStore.open = true;
|
|
|
|
|
$snackbarStore.message = 'Update successful';
|
|
|
|
|
$snackbarStore.severity = SNACKBAR_SEVERITY.SUCCESS;
|
|
|
|
|
|
|
|
|
|
if (error) throw error;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
let message = error.message;
|
|
|
|
|
if (message.includes('profile_username_key')) {
|
|
|
|
|
message = 'username already exists';
|
|
|
|
|
}
|
|
|
|
|
$snackbarStore.open = true;
|
|
|
|
|
$snackbarStore.message = `Update failed: ${message}`;
|
|
|
|
|
$snackbarStore.severity = SNACKBAR_SEVERITY.ERROR;
|
|
|
|
|
loading = false;
|
|
|
|
|
} finally {
|
|
|
|
|
loading = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function gotoSetting(pathname) {
|
2023-05-20 23:53:28 +00:00
|
|
|
goto(`${$currentOrgPath}/settings${pathname}`);
|
2023-05-02 23:55:26 +00:00
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2023-05-11 15:15:18 +00:00
|
|
|
<Grid class="border-c rounded border-gray-200 w-full mt-5">
|
|
|
|
|
<Row class="py-7 border-bottom-c">
|
2023-05-05 20:19:45 +00:00
|
|
|
<Column sm={2} md={2} lg={4}
|
|
|
|
|
><SectionTitle>Organization Profile</SectionTitle></Column
|
|
|
|
|
>
|
2023-05-02 23:55:26 +00:00
|
|
|
<Column sm={2} md={6} lg={8}>
|
|
|
|
|
<TextField
|
|
|
|
|
label="Organization Name"
|
|
|
|
|
bind:value={$currentOrg.name}
|
|
|
|
|
className="w-60 mb-5"
|
|
|
|
|
/>
|
|
|
|
|
<UploadImage
|
|
|
|
|
bind:avatar
|
|
|
|
|
src={$currentOrg.avatar_url}
|
|
|
|
|
shape="rounded-md"
|
|
|
|
|
widthHeight="w-24 h-24"
|
|
|
|
|
/>
|
|
|
|
|
<PrimaryButton
|
|
|
|
|
label="Update Organization"
|
|
|
|
|
className="px-6 py-3 mr-5 mt-5"
|
|
|
|
|
isLoading={loading}
|
|
|
|
|
isDisabled={loading}
|
|
|
|
|
onClick={handleUpdate}
|
|
|
|
|
/>
|
|
|
|
|
</Column>
|
|
|
|
|
</Row>
|
2023-05-11 15:15:18 +00:00
|
|
|
<!-- <Row class="py-7 border-bottom-c">
|
2023-05-05 20:19:45 +00:00
|
|
|
<Column sm={2} md={2} lg={4}><SectionTitle>Theme</SectionTitle></Column>
|
2023-05-02 23:55:26 +00:00
|
|
|
<Column sm={2} md={6} lg={8}>
|
2023-05-05 20:19:45 +00:00
|
|
|
<h4 class="dark:text-white">Set your brand</h4>
|
2023-05-02 23:55:26 +00:00
|
|
|
</Column>
|
|
|
|
|
</Row> -->
|
2023-05-11 15:15:18 +00:00
|
|
|
<Row class="py-7 border-bottom-c">
|
2023-05-05 20:19:45 +00:00
|
|
|
<Column sm={2} md={2} lg={4}
|
|
|
|
|
><SectionTitle>Custom Domain</SectionTitle></Column
|
|
|
|
|
>
|
2023-05-02 23:55:26 +00:00
|
|
|
<Column sm={2} md={6} lg={8}>
|
2023-05-05 20:19:45 +00:00
|
|
|
<h4 class="dark:text-white">Customise your Domain</h4>
|
2023-06-17 19:11:29 +00:00
|
|
|
<p class="text-sm text-gray-500 dark:text-white">
|
2023-05-02 23:55:26 +00:00
|
|
|
Create a custom URL so your audience can get to your organization easily
|
|
|
|
|
</p>
|
|
|
|
|
<PrimaryButton
|
|
|
|
|
label="Edit domain"
|
|
|
|
|
className="my-7 py-5 px-10 text-blue-700"
|
|
|
|
|
variant={VARIANTS.OUTLINED}
|
|
|
|
|
onClick={() => gotoSetting('/domains')}
|
|
|
|
|
/>
|
|
|
|
|
</Column>
|
|
|
|
|
</Row>
|
2023-05-11 15:15:18 +00:00
|
|
|
<Row class="py-7 border-bottom-c">
|
2023-05-05 20:19:45 +00:00
|
|
|
<Column sm={2} md={2} lg={4}><SectionTitle>Team</SectionTitle></Column>
|
2023-05-02 23:55:26 +00:00
|
|
|
<Column sm={2} md={6} lg={8}>
|
2023-05-05 20:19:45 +00:00
|
|
|
<h4 class="dark:text-white">Set up your website</h4>
|
2023-06-17 19:11:29 +00:00
|
|
|
<p class="text-sm text-gray-500 dark:text-white">
|
2023-05-02 23:55:26 +00:00
|
|
|
Add team mates to your organization so you can both collaborate on
|
|
|
|
|
projects.
|
|
|
|
|
</p>
|
|
|
|
|
<PrimaryButton
|
|
|
|
|
label="Manage Team"
|
|
|
|
|
className="my-7 py-5 px-10 text-blue-700"
|
|
|
|
|
variant={VARIANTS.OUTLINED}
|
|
|
|
|
onClick={() => gotoSetting('/teams')}
|
|
|
|
|
/>
|
|
|
|
|
</Column>
|
|
|
|
|
</Row>
|
|
|
|
|
</Grid>
|