Skip to content

Commit ff42fcf

Browse files
committed
feat: add attachment support to support wizard
1 parent 345acee commit ff42fcf

1 file changed

Lines changed: 60 additions & 18 deletions

File tree

src/routes/(console)/supportWizard.svelte

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
<script lang="ts">
22
import { Wizard } from '$lib/layout';
3-
import { Icon, Input, Layout, Popover, Tag, Typography, Card } from '@appwrite.io/pink-svelte';
3+
import {
4+
Icon,
5+
Input,
6+
Layout,
7+
Popover,
8+
Tag,
9+
Typography,
10+
Card,
11+
Upload
12+
} from '@appwrite.io/pink-svelte';
413
import { supportData, isSupportOnline } from './wizard/support/store';
514
import { onMount, onDestroy } from 'svelte';
615
import { sdk } from '$lib/stores/sdk';
@@ -25,8 +34,10 @@
2534
import { wizard } from '$lib/stores/wizard';
2635
import { VARS } from '$lib/system';
2736
import { IconCheckCircle, IconXCircle, IconInfo } from '@appwrite.io/pink-icons-svelte';
37+
import { removeFile } from '$lib/helpers/files';
2838
2939
let projectOptions = $state<Array<{ value: string; label: string }>>([]);
40+
let files = $state<FileList | null>(null);
3041
3142
// Category options with display names
3243
const categories = [
@@ -101,25 +112,29 @@
101112
? `${$supportData.category}-${$supportData.topic}`.toLowerCase()
102113
: $supportData.category.toLowerCase();
103114
115+
const formData = new FormData();
116+
formData.append('email', $user.email);
117+
formData.append('subject', $supportData.subject);
118+
formData.append('firstName', ($user?.name || 'Unknown').slice(0, 40));
119+
formData.append('message', $supportData.message);
120+
formData.append('tags[]', categoryTopicTag);
121+
formData.append(
122+
'customFields',
123+
JSON.stringify([
124+
{ id: '41612', value: $supportData.category },
125+
{ id: '48492', value: $organization?.$id ?? '' },
126+
{ id: '48491', value: $supportData?.project ?? '' },
127+
{ id: '56023', value: $supportData?.severity ?? '' },
128+
{ id: '56024', value: $organization?.billingPlan ?? '' }
129+
])
130+
);
131+
if (files && files.length > 0) {
132+
formData.append('attachment', files[0]);
133+
}
134+
104135
const response = await fetch(`${VARS.GROWTH_ENDPOINT}/support`, {
105136
method: 'POST',
106-
headers: {
107-
'Content-Type': 'application/json'
108-
},
109-
body: JSON.stringify({
110-
email: $user.email,
111-
subject: $supportData.subject,
112-
firstName: ($user?.name || 'Unknown').slice(0, 40),
113-
message: $supportData.message,
114-
tags: [categoryTopicTag],
115-
customFields: [
116-
{ id: '41612', value: $supportData.category },
117-
{ id: '48492', value: $organization?.$id ?? '' },
118-
{ id: '48491', value: $supportData?.project ?? '' },
119-
{ id: '56023', value: $supportData?.severity ?? '' },
120-
{ id: '56024', value: $organization?.billingPlan ?? '' }
121-
]
122-
})
137+
body: formData
123138
});
124139
trackEvent(Submit.SupportTicket);
125140
if (response.status !== 200) {
@@ -154,6 +169,13 @@
154169
155170
$wizard.finalAction = handleSubmit;
156171
172+
function handleInvalid(_e: CustomEvent) {
173+
addNotification({
174+
type: 'error',
175+
message: 'Invalid file'
176+
});
177+
}
178+
157179
const workTimings = {
158180
start: '16:00',
159181
end: '00:00',
@@ -264,6 +286,26 @@
264286
label="Tell us a bit more"
265287
required
266288
maxlength={4096} />
289+
<Upload.Dropzone bind:files on:invalid={handleInvalid} maxSize={5 * 1024 * 1024}>
290+
<Layout.Stack alignItems="center" gap="s">
291+
<Typography.Text variant="l-500"
292+
>Drag and drop a file here or click to upload</Typography.Text>
293+
<Typography.Caption variant="400">Max file size: 5MB</Typography.Caption>
294+
</Layout.Stack>
295+
</Upload.Dropzone>
296+
{#if files}
297+
<Upload.List
298+
files={Array.from(files).map((f) => {
299+
return {
300+
...f,
301+
name: f.name,
302+
size: f.size,
303+
extension: f.type,
304+
removable: true
305+
};
306+
})}
307+
on:remove={(e) => (files = removeFile(e.detail, files))} />
308+
{/if}
267309
<Layout.Stack direction="row" justifyContent="flex-end" gap="s">
268310
<Button
269311
size="s"

0 commit comments

Comments
 (0)