Merge branch 'main' of github.com:appwrite/console into refactor-org-creation

This commit is contained in:
Arman committed 2024-05-14 15:02:01 +02:00
commit 8985bdc27a
10 files changed
+158 -52

No files matched your search

+4 -1
View File
@@ -9,12 +9,15 @@
import { BillingPlan } from '$lib/constants';
import ChangeOrganizationTierCloud from '$routes/console/changeOrganizationTierCloud.svelte';
import { trackEvent } from '$lib/actions/analytics';
import { localeTimezoneName, utcHourToLocaleHour } from '$lib/helpers/date';
export let show = false;
$: isPaid =
$organization?.billingPlan === BillingPlan.PRO ||
$organization?.billingPlan === BillingPlan.SCALE;
$: supportTimings = `${utcHourToLocaleHour('09:00')} - ${utcHourToLocaleHour('17:00')} ${localeTimezoneName()}`;
</script>
{#if isCloud}
@@ -23,7 +26,7 @@
<h4 class="eyebrow-heading-3">Premium support</h4>
{#if isPaid}
<p class="u-line-height-1-5 u-margin-block-start-8">
Get personalized support from the Appwrite team from <b>09:00 - 17:00 UTC</b>
Get personalized support from the Appwrite team from <b>{supportTimings}</b>
</p>
{/if}
</div>
+55
View File
@@ -2,6 +2,15 @@ import { browser } from '$app/environment';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
export type WeekDay =
| 'Sunday'
| 'Monday'
| 'Tuesday'
| 'Wednesday'
| 'Thursday'
| 'Friday'
| 'Saturday';
if (browser) {
dayjs.extend(relativeTime);
}
@@ -73,6 +82,52 @@ export const toLocaleTimeISO = (datetime: string | number) => {
return date.toLocaleTimeString('sv');
};
export const utcHourToLocaleHour = (utcTimeString: string) => {
const now = new Date();
const [hours, minutes] = utcTimeString.split(':').map(Number);
const customTime = Date.UTC(now.getFullYear(), now.getMonth(), now.getDate(), hours, minutes);
const options: Intl.DateTimeFormatOptions = {
hour: 'numeric',
minute: 'numeric',
hourCycle: 'h23'
};
return new Intl.DateTimeFormat('en', options).format(new Date(customTime));
};
export const utcWeekDayToLocaleWeekDay = (utcDay: WeekDay, utcTimeString: string) => {
const now = new Date();
const daysOfTheWeek = {
Sunday: 0,
Monday: 1,
Tuesday: 2,
Wednesday: 3,
Thursday: 4,
Friday: 5,
Saturday: 6
};
const utcDayNumber = daysOfTheWeek[utcDay];
const [hours, minutes] = utcTimeString.split(':').map(Number);
const daysUntilNextUtcDay = (7 + utcDayNumber - now.getUTCDay()) % 7;
now.setUTCDate(now.getUTCDate() + daysUntilNextUtcDay);
now.setUTCHours(hours, minutes, 0, 0);
return new Intl.DateTimeFormat('en', { weekday: 'short' }).format(now);
};
export const localeTimezoneName = () => {
const options: Intl.DateTimeFormatOptions = {
timeZoneName: 'longGeneric'
};
const dateWithTimezone = new Intl.DateTimeFormat('en', options).format(new Date());
return dateWithTimezone.split(', ')[1];
};
export const isSameDay = (date1: Date, date2: Date) => {
return (
date1.getFullYear() === date2.getFullYear() &&
@@ -103,25 +103,23 @@
</div>
{:then installations}
{#if hasInstallations}
<div class="u-flex u-gap-16">
<div class="u-width-full-line">
<InputSelect
id="installation"
label="Git organization"
options={installations.map((entry) => {
return {
label: entry.organization,
value: entry.$id
};
})}
on:change={() => {
$installation = installations.find(
(entry) => entry.$id === selectedInstallationId
);
}}
bind:value={selectedInstallationId} />
</div>
</div>
<FormList>
<InputSelect
id="installation"
label="Git organization"
options={installations.map((entry) => {
return {
label: entry.organization,
value: entry.$id
};
})}
on:change={() => {
$installation = installations.find(
(entry) => entry.$id === selectedInstallationId
);
}}
bind:value={selectedInstallationId} />
</FormList>
{:else}
<div class="u-flex u-cross-center u-flex-vertical u-gap-16">
<Button href={connectGitHub().toString()} fullWidth secondary>
@@ -47,7 +47,6 @@ export const load: LayoutLoad = async ({ params, depends }) => {
const prefs = await sdk.forConsole.account.getPrefs();
const newPrefs = { ...prefs, organization: null };
sdk.forConsole.account.updatePrefs(newPrefs);
localStorage.removeItem('organization');
error(e.code, e.message);
}
};
@@ -24,22 +24,17 @@
} else {
await sdk.forConsole.teams.delete($organization.$id);
}
await invalidate(Dependencies.ACCOUNT);
await invalidate(Dependencies.ORGANIZATION);
trackEvent(Submit.OrganizationDelete);
const prefs = await sdk.forConsole.account.getPrefs();
const newPrefs = { ...prefs, organization: null };
await sdk.forConsole.account.updatePrefs(newPrefs);
if ($organizationList?.total > 1) {
const account = await sdk.forConsole.account.get();
const teamId =
account.prefs.organization ??
$organizationList.teams[0].$id === $organization.$id
? $organizationList.teams[1].$id
: $organizationList.teams[0].$id;
await goto(`${base}/console/organization-${teamId}`);
await goto(`${base}/console/account/organizations`);
} else {
await goto(`${base}/console/onboarding`);
}
await invalidate(Dependencies.ACCOUNT);
await invalidate(Dependencies.ORGANIZATION);
trackEvent(Submit.OrganizationDelete);
showDelete = false;
addNotification({
type: 'success',
@@ -1,5 +1,5 @@
<script context="module" lang="ts">
import { Query, type Models, RelationshipType, RelationMutate } from '@appwrite.io/console';
import { ID, Query, type Models, RelationshipType, RelationMutate } from '@appwrite.io/console';
import { sdk } from '$lib/stores/sdk';
export async function submitRelationship(
@@ -21,7 +21,7 @@
data.relationType,
data.twoWay,
data.key,
data.twoWayKey,
data.twoWayKey ?? ID.unique(),
data.onDelete
);
}
@@ -24,10 +24,12 @@
import Status from '$lib/components/status.svelte';
import { capitalize } from '$lib/helpers/string';
import { readOnly } from '$lib/stores/billing';
import type { Models } from '@appwrite.io/console';
export let data;
let details: string | null = null;
let migration: Models.Migration = null;
let showExport = false;
let showMigration = false;
const getStatus = (status: string) => {
if (status === 'failed') {
@@ -129,6 +131,11 @@
// JSON.stringify(migrationData)
// )}`;
};
function showDetails(m: Models.Migration) {
showMigration = true;
migration = m;
}
</script>
<Container>
@@ -182,7 +189,7 @@
</TableCell>
<TableCell title="">
<div class="u-flex u-main-end">
<Button secondary on:click={() => (details = entry.$id)}
<Button secondary on:click={() => showDetails(entry)}
>Details</Button>
</div>
</TableCell>
@@ -296,7 +303,7 @@
<ExportModal bind:show={showExport} />
<Details bind:migrationId={details} migrations={data.migrations} />
<Details {migration} bind:show={showMigration} />
<style lang="scss">
.import-box {
@@ -8,12 +8,8 @@
import type { Models } from '@appwrite.io/console';
import { ResourcesFriendly } from '$lib/stores/migration';
export let migrations: Models.Migration[] = [];
export let migrationId: string = null;
$: details = migrations.find((migration) => migration.$id === migrationId);
$: show = !!details && migrationId !== null;
export let migration: Models.Migration = null;
export let show = false;
type StatusCounters = {
[resource in 'Database' | 'Collection' | 'Function' | 'Users']?: StatusCounter;
@@ -23,7 +19,7 @@
};
$: statusCounters = parseIfString(
(details?.statusCounters as unknown as string) || '{}'
(migration?.statusCounters as unknown as string) || '{}'
) as StatusCounters;
const hasError = (counter: StatusCounter) => {
@@ -49,9 +45,9 @@
let tab = 'details' as 'details' | 'logs';
</script>
<Modal bind:show on:close={() => (migrationId = null)} size="big">
<Modal bind:show size="big">
<svelte:fragment slot="title">
{#if details.status === 'failed'}
{#if migration.status === 'failed'}
Resolve migration issues
{:else}
Migration details
@@ -63,13 +59,13 @@
</Tabs>
{#if tab === 'logs'}
<Code code={JSON.stringify(details, null, 2)} language="json" allowScroll />
<Code code={JSON.stringify(migration, null, 2)} language="json" allowScroll />
{:else if tab === 'details'}
<div class="box meta">
<span>Date</span>
<span>{toLocaleDateTime(details.$createdAt)}</span>
<span>{toLocaleDateTime(migration.$createdAt)}</span>
<span>Source</span>
<span>{details.source}</span>
<span>{migration.source}</span>
</div>
{#if Object.values(statusCounters).some(hasError)}
+19 -1
View File
@@ -10,6 +10,12 @@
import { wizard } from '$lib/stores/wizard';
import { VARS } from '$lib/system';
import { organization } from '$lib/stores/organization';
import {
localeTimezoneName,
utcHourToLocaleHour,
utcWeekDayToLocaleWeekDay,
type WeekDay
} from '$lib/helpers/date';
onDestroy(() => {
$supportData = {
@@ -76,6 +82,16 @@
}
$wizard.finalAction = handleSubmit;
const workTimings = {
start: '09:00',
end: '17:00',
startDay: 'Monday' as WeekDay,
endDay: 'Friday' as WeekDay
};
$: supportTimings = `${utcHourToLocaleHour(workTimings.start)} - ${utcHourToLocaleHour(workTimings.end)} ${localeTimezoneName()}`;
$: supportWeekDays = `${utcWeekDayToLocaleWeekDay(workTimings.startDay, workTimings.start)} - ${utcWeekDayToLocaleWeekDay(workTimings.endDay, workTimings.end)}`;
</script>
<Wizard title="Contact us" steps={stepsComponents} finalAction="Submit" on:exit={resetData}>
@@ -85,7 +101,9 @@
If you found a bug or have questions, please reach out to the Appwrite team. We try to
respond to all messages within our office hours.
</p>
<p class="text u-margin-block-start-32">Available: <b>Mon-Fri 09:00 - 17:00 UTC</b></p>
<p class="text u-margin-block-start-32">
Available: <b>{supportWeekDays}, {supportTimings}</b>
</p>
<div class="u-flex u-gap-4 u-cross-center">
<span>Currently:</span>
{#if isSupportOnline()}
+36 -1
View File
@@ -1,4 +1,5 @@
import '@testing-library/jest-dom';
import type { WeekDay } from '$lib/helpers/date';
import {
toLocaleDate,
toLocaleDateTime,
@@ -6,7 +7,9 @@ import {
isValidDate,
diffDays,
toLocaleDateISO,
toLocaleTimeISO
toLocaleTimeISO,
utcHourToLocaleHour,
utcWeekDayToLocaleWeekDay
} from '$lib/helpers/date';
describe('local date', () => {
@@ -121,3 +124,35 @@ describe('diff days', () => {
});
});
});
describe('utc hour to local hour', () => {
const entries: Array<[string, string]> = [
['09:00', '04:00'],
['10:45', '05:45'],
['11:59', '06:59'],
['17:00', '12:00'],
['22:36', '17:36']
];
entries.forEach(([value, expected]) => {
it(value, () => {
expect(utcHourToLocaleHour(value)).toBe(expected);
});
});
});
describe('utc week day to local week day', () => {
const entries: Array<[WeekDay, string, string]> = [
['Sunday', '00:00', 'Sat'],
['Sunday', '22:00', 'Sun'],
['Wednesday', '13:00', 'Wed'],
['Friday', '23:59', 'Fri'],
['Saturday', '10:00', 'Sat']
];
entries.forEach(([weekDay, utcTimeString, expected]) => {
it(`${weekDay} ${utcTimeString}`, () => {
expect(utcWeekDayToLocaleWeekDay(weekDay, utcTimeString)).toBe(expected);
});
});
});