Skip to content

Commit f5f5883

Browse files
committed
feat: add attachment support to support wizard
1 parent a2667f8 commit f5f5883

File tree

1 file changed

+60
-18
lines changed

1 file changed

+60
-18
lines changed

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 = [
@@ -116,25 +127,29 @@
116127
? `${$supportData.category}-${$supportData.topic}`.toLowerCase()
117128
: $supportData.category.toLowerCase();
118129
130+
const formData = new FormData();
131+
formData.append('email', $user.email);
132+
formData.append('subject', $supportData.subject);
133+
formData.append('firstName', ($user?.name || 'Unknown').slice(0, 40));
134+
formData.append('message', $supportData.message);
135+
formData.append('tags[]', categoryTopicTag);
136+
formData.append(
137+
'customFields',
138+
JSON.stringify([
139+
{ id: '41612', value: $supportData.category },
140+
{ id: '48492', value: $organization?.$id ?? '' },
141+
{ id: '48491', value: $supportData?.project ?? '' },
142+
{ id: '56023', value: $supportData?.severity ?? '' },
143+
{ id: '56024', value: $organization?.billingPlan ?? '' }
144+
])
145+
);
146+
if (files && files.length > 0) {
147+
formData.append('attachment', files[0]);
148+
}
149+
119150
const response = await fetch(`${VARS.GROWTH_ENDPOINT}/support`, {
120151
method: 'POST',
121-
headers: {
122-
'Content-Type': 'application/json'
123-
},
124-
body: JSON.stringify({
125-
email: $user.email,
126-
subject: $supportData.subject,
127-
firstName: ($user?.name || 'Unknown').slice(0, 40),
128-
message: $supportData.message,
129-
tags: [categoryTopicTag],
130-
customFields: [
131-
{ id: '41612', value: $supportData.category },
132-
{ id: '48492', value: $organization?.$id ?? '' },
133-
{ id: '48491', value: $supportData?.project ?? '' },
134-
{ id: '56023', value: $supportData?.severity ?? '' },
135-
{ id: '56024', value: $organization?.billingPlan ?? '' }
136-
]
137-
})
152+
body: formData
138153
});
139154
trackEvent(Submit.SupportTicket);
140155
if (response.status !== 200) {
@@ -169,6 +184,13 @@
169184
170185
$wizard.finalAction = handleSubmit;
171186
187+
function handleInvalid(_e: CustomEvent) {
188+
addNotification({
189+
type: 'error',
190+
message: 'Invalid file'
191+
});
192+
}
193+
172194
const workTimings = {
173195
start: '16:00',
174196
end: '00:00',
@@ -279,6 +301,26 @@
279301
label="Tell us a bit more"
280302
required
281303
maxlength={4096} />
304+
<Upload.Dropzone bind:files on:invalid={handleInvalid} maxSize={5 * 1024 * 1024}>
305+
<Layout.Stack alignItems="center" gap="s">
306+
<Typography.Text variant="l-500"
307+
>Drag and drop a file here or click to upload</Typography.Text>
308+
<Typography.Caption variant="400">Max file size: 5MB</Typography.Caption>
309+
</Layout.Stack>
310+
</Upload.Dropzone>
311+
{#if files}
312+
<Upload.List
313+
files={Array.from(files).map((f) => {
314+
return {
315+
...f,
316+
name: f.name,
317+
size: f.size,
318+
extension: f.type,
319+
removable: true
320+
};
321+
})}
322+
on:remove={(e) => (files = removeFile(e.detail, files))} />
323+
{/if}
282324
<Layout.Stack direction="row" justifyContent="flex-end" gap="s">
283325
<Button
284326
size="s"

0 commit comments

Comments
 (0)