mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
feat: add attachment support to support wizard (#2624)
This commit is contained in:
1 parent
4425d99e6b
commit
e446f7ff82
1 file changed
+60
-18
@@ -1,6 +1,15 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Wizard } from '$lib/layout';
|
import { Wizard } from '$lib/layout';
|
||||||
import { Icon, Input, Layout, Popover, Tag, Typography, Card } from '@appwrite.io/pink-svelte';
|
import {
|
||||||
|
Icon,
|
||||||
|
Input,
|
||||||
|
Layout,
|
||||||
|
Popover,
|
||||||
|
Tag,
|
||||||
|
Typography,
|
||||||
|
Card,
|
||||||
|
Upload
|
||||||
|
} from '@appwrite.io/pink-svelte';
|
||||||
import { supportData, isSupportOnline } from './wizard/support/store';
|
import { supportData, isSupportOnline } from './wizard/support/store';
|
||||||
import { onMount, onDestroy } from 'svelte';
|
import { onMount, onDestroy } from 'svelte';
|
||||||
import { sdk } from '$lib/stores/sdk';
|
import { sdk } from '$lib/stores/sdk';
|
||||||
@@ -25,8 +34,10 @@
|
|||||||
import { wizard } from '$lib/stores/wizard';
|
import { wizard } from '$lib/stores/wizard';
|
||||||
import { VARS } from '$lib/system';
|
import { VARS } from '$lib/system';
|
||||||
import { IconCheckCircle, IconXCircle, IconInfo } from '@appwrite.io/pink-icons-svelte';
|
import { IconCheckCircle, IconXCircle, IconInfo } from '@appwrite.io/pink-icons-svelte';
|
||||||
|
import { removeFile } from '$lib/helpers/files';
|
||||||
|
|
||||||
let projectOptions = $state<Array<{ value: string; label: string }>>([]);
|
let projectOptions = $state<Array<{ value: string; label: string }>>([]);
|
||||||
|
let files = $state<FileList | null>(null);
|
||||||
|
|
||||||
// Category options with display names
|
// Category options with display names
|
||||||
const categories = [
|
const categories = [
|
||||||
@@ -118,25 +129,29 @@
|
|||||||
? `${$supportData.category}-${$supportData.topic}`.toLowerCase()
|
? `${$supportData.category}-${$supportData.topic}`.toLowerCase()
|
||||||
: $supportData.category.toLowerCase();
|
: $supportData.category.toLowerCase();
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('email', $user.email);
|
||||||
|
formData.append('subject', $supportData.subject);
|
||||||
|
formData.append('firstName', ($user?.name || 'Unknown').slice(0, 40));
|
||||||
|
formData.append('message', $supportData.message);
|
||||||
|
formData.append('tags[]', categoryTopicTag);
|
||||||
|
formData.append(
|
||||||
|
'customFields',
|
||||||
|
JSON.stringify([
|
||||||
|
{ id: '41612', value: $supportData.category },
|
||||||
|
{ id: '48492', value: $organization?.$id ?? '' },
|
||||||
|
{ id: '48491', value: $supportData?.project ?? '' },
|
||||||
|
{ id: '56023', value: $supportData?.severity ?? '' },
|
||||||
|
{ id: '56024', value: $organization?.billingPlan ?? '' }
|
||||||
|
])
|
||||||
|
);
|
||||||
|
if (files && files.length > 0) {
|
||||||
|
formData.append('attachment', files[0]);
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(`${VARS.GROWTH_ENDPOINT}/support`, {
|
const response = await fetch(`${VARS.GROWTH_ENDPOINT}/support`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
body: formData
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
email: $user.email,
|
|
||||||
subject: $supportData.subject,
|
|
||||||
firstName: ($user?.name || 'Unknown').slice(0, 40),
|
|
||||||
message: $supportData.message,
|
|
||||||
tags: [categoryTopicTag],
|
|
||||||
customFields: [
|
|
||||||
{ id: '41612', value: $supportData.category },
|
|
||||||
{ id: '48492', value: $organization?.$id ?? '' },
|
|
||||||
{ id: '48491', value: $supportData?.project ?? '' },
|
|
||||||
{ id: '56023', value: $supportData?.severity ?? '' },
|
|
||||||
{ id: '56024', value: $organization?.billingPlan ?? '' }
|
|
||||||
]
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
trackEvent(Submit.SupportTicket);
|
trackEvent(Submit.SupportTicket);
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
@@ -171,6 +186,13 @@
|
|||||||
|
|
||||||
$wizard.finalAction = handleSubmit;
|
$wizard.finalAction = handleSubmit;
|
||||||
|
|
||||||
|
function handleInvalid(_e: CustomEvent) {
|
||||||
|
addNotification({
|
||||||
|
type: 'error',
|
||||||
|
message: 'Invalid file'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const workTimings = {
|
const workTimings = {
|
||||||
start: '16:00',
|
start: '16:00',
|
||||||
end: '00:00',
|
end: '00:00',
|
||||||
@@ -281,6 +303,26 @@
|
|||||||
label="Tell us a bit more"
|
label="Tell us a bit more"
|
||||||
required
|
required
|
||||||
maxlength={4096} />
|
maxlength={4096} />
|
||||||
|
<Upload.Dropzone bind:files on:invalid={handleInvalid} maxSize={5 * 1024 * 1024}>
|
||||||
|
<Layout.Stack alignItems="center" gap="s">
|
||||||
|
<Typography.Text variant="l-500"
|
||||||
|
>Drag and drop a file here or click to upload</Typography.Text>
|
||||||
|
<Typography.Caption variant="400">Max file size: 5MB</Typography.Caption>
|
||||||
|
</Layout.Stack>
|
||||||
|
</Upload.Dropzone>
|
||||||
|
{#if files}
|
||||||
|
<Upload.List
|
||||||
|
files={Array.from(files).map((f) => {
|
||||||
|
return {
|
||||||
|
...f,
|
||||||
|
name: f.name,
|
||||||
|
size: f.size,
|
||||||
|
extension: f.type,
|
||||||
|
removable: true
|
||||||
|
};
|
||||||
|
})}
|
||||||
|
on:remove={(e) => (files = removeFile(e.detail, files))} />
|
||||||
|
{/if}
|
||||||
<Layout.Stack direction="row" justifyContent="flex-end" gap="s">
|
<Layout.Stack direction="row" justifyContent="flex-end" gap="s">
|
||||||
<Button
|
<Button
|
||||||
size="s"
|
size="s"
|
||||||
|
|||||||
Reference in new issue
Block a user