|
7 | 7 | import { organization } from '$lib/stores/organization'; |
8 | 8 | import { user } from '$lib/stores/user'; |
9 | 9 | import { VARS } from '$lib/system'; |
10 | | - import { onMount } from 'svelte'; |
| 10 | + import { untrack } from 'svelte'; |
11 | 11 | import type { Models } from '@appwrite.io/console'; |
12 | 12 |
|
13 | | - export let show = false; |
14 | | - export let locale: Models.Locale; |
15 | | - export let countryList: Models.CountryList; |
| 13 | + let { |
| 14 | + show = $bindable(false), |
| 15 | + locale, |
| 16 | + countryList |
| 17 | + }: { |
| 18 | + show?: boolean; |
| 19 | + locale: Models.Locale; |
| 20 | + countryList: Models.CountryList; |
| 21 | + } = $props(); |
16 | 22 |
|
17 | | - let email = ''; |
18 | | - let employees: string = null; |
19 | | - let employeesOptions = [ |
| 23 | + let email = $state($user?.email ?? ''); |
| 24 | + let employees = $state<string>(null); |
| 25 | + const employeesOptions = [ |
20 | 26 | { |
21 | 27 | value: '1-5', |
22 | 28 | label: '1-5' |
|
35 | 41 | } |
36 | 42 | ]; |
37 | 43 |
|
38 | | - let country = ''; |
39 | | - let countryOptions = []; |
40 | | -
|
41 | | - let role = ''; |
42 | | - let website = ''; |
43 | | -
|
44 | | - let error: string; |
45 | | -
|
46 | | - onMount(async () => { |
47 | | - if (locale.countryCode) { |
48 | | - country = locale.countryCode; |
49 | | - } |
50 | | - countryOptions = countryList.countries.map((country) => { |
| 44 | + let country = $state(untrack(() => locale?.countryCode ?? '')); |
| 45 | + const countryOptions = $derived( |
| 46 | + (countryList?.countries ?? []).map((country) => { |
51 | 47 | return { |
52 | 48 | value: country.code, |
53 | 49 | label: country.name |
54 | 50 | }; |
55 | | - }); |
56 | | - email = $user.email; |
57 | | - }); |
| 51 | + }) |
| 52 | + ); |
| 53 | +
|
| 54 | + let role = $state(''); |
| 55 | + let website = $state(''); |
| 56 | +
|
| 57 | + let error = $state<string>(null); |
58 | 58 |
|
59 | 59 | async function handleSubmit() { |
| 60 | + const formData = new FormData(); |
| 61 | + formData.append('subject', 'SOC-2 Request'); |
| 62 | + formData.append('email', email); |
| 63 | + formData.append('firstName', ($user?.name ?? '').slice(0, 40)); |
| 64 | + formData.append( |
| 65 | + 'message', |
| 66 | + `SOC-2 request for ${$organization?.name ?? ''} (${$organization?.$id ?? ''})` |
| 67 | + ); |
| 68 | + formData.append('tags[]', 'cloud'); |
| 69 | + formData.append( |
| 70 | + 'metaFields', |
| 71 | + JSON.stringify({ |
| 72 | + category: 'SOC-2', |
| 73 | + userName: $user?.name ?? '', |
| 74 | + orgId: $organization?.$id ?? '', |
| 75 | + userId: $user?.$id ?? '', |
| 76 | + billingPlan: $organization?.billingPlanId ?? '', |
| 77 | + employees: employees, |
| 78 | + country: country, |
| 79 | + role: role, |
| 80 | + website: website |
| 81 | + }) |
| 82 | + ); |
| 83 | +
|
60 | 84 | const response = await fetch(`${VARS.GROWTH_ENDPOINT}/support`, { |
61 | 85 | method: 'POST', |
62 | | - headers: { |
63 | | - 'Content-Type': 'application/json' |
64 | | - }, |
65 | | - body: JSON.stringify({ |
66 | | - subject: 'SOC-2 Request', |
67 | | - email: email, |
68 | | - firstName: ($user?.name ?? '').slice(0, 40), |
69 | | - message: `SOC-2 request for ${$organization?.name ?? ''} (${$organization?.$id ?? ''})`, |
70 | | - tags: ['cloud'], |
71 | | - metaFields: { |
72 | | - category: 'SOC-2', |
73 | | - userName: $user?.name ?? '', |
74 | | - orgId: $organization?.$id ?? '', |
75 | | - userId: $user?.$id ?? '', |
76 | | - employees: employees, |
77 | | - country: country, |
78 | | - role: role, |
79 | | - website: website |
80 | | - } |
81 | | - }) |
| 86 | + body: formData |
82 | 87 | }); |
83 | 88 | trackEvent(Submit.RequestSoc2); |
84 | 89 | if (response.status !== 200) { |
|
0 commit comments