2023-09-26 11:57:31 +01:00
|
|
|
<script lang="ts">
|
2023-09-26 09:01:53 +00:00
|
|
|
import { profile } from '$lib/utils/store/user';
|
2025-11-21 12:18:04 +01:00
|
|
|
import { t } from '$lib/utils/functions/translations';
|
|
|
|
|
import { supabase } from '$lib/utils/functions/supabase';
|
2023-09-27 05:35:06 +01:00
|
|
|
import { snackbar } from '$lib/components/Snackbar/store';
|
2025-11-21 12:18:04 +01:00
|
|
|
import { VARIANTS } from '$lib/components/PrimaryButton/constants';
|
|
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
import { Row, Grid, Column } from './Layout';
|
2025-11-21 12:18:04 +01:00
|
|
|
import SectionTitle from '../SectionTitle.svelte';
|
2023-09-26 09:01:53 +00:00
|
|
|
import TextField from '$lib/components/Form/TextField.svelte';
|
|
|
|
|
import PrimaryButton from '$lib/components/PrimaryButton/index.svelte';
|
2023-09-26 11:57:31 +01:00
|
|
|
import ArrowUpRightIcon from '$lib/components/Icons/ArrowTopRight.svelte';
|
2025-11-21 12:18:04 +01:00
|
|
|
import CircleCheckIcon from '$lib/components/Icons/CircleCheckIcon.svelte';
|
2023-09-26 09:01:53 +00:00
|
|
|
|
2025-11-01 15:49:29 +01:00
|
|
|
let chatId: number | null = $state(null);
|
2023-09-26 09:01:53 +00:00
|
|
|
|
|
|
|
|
async function addChatId() {
|
2023-09-27 05:35:06 +01:00
|
|
|
if (!chatId || `${chatId}`.length < 5) return;
|
2023-09-26 09:01:53 +00:00
|
|
|
|
2023-09-27 05:35:06 +01:00
|
|
|
const { error } = await supabase
|
|
|
|
|
.from('profile')
|
|
|
|
|
.update({
|
|
|
|
|
telegram_chat_id: chatId
|
|
|
|
|
})
|
|
|
|
|
.match({ id: $profile.id });
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
console.log(error);
|
2024-04-19 05:45:48 +01:00
|
|
|
snackbar.error('snackbar.course_settings.error.failed_integration');
|
2023-09-27 05:35:06 +01:00
|
|
|
} else {
|
2025-11-24 01:00:50 +01:00
|
|
|
$profile.telegramChatId = chatId;
|
2023-09-27 05:35:06 +01:00
|
|
|
chatId = null;
|
2024-04-19 05:45:48 +01:00
|
|
|
snackbar.success('snackbar.course_settings.success.successful_integration');
|
2023-09-26 09:01:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function deleteChatId() {
|
2025-11-01 15:49:29 +01:00
|
|
|
const { error } = await supabase.from('profile').update({ telegram_chat_id: null }).match({ id: $profile.id });
|
2023-09-26 09:01:53 +00:00
|
|
|
|
2023-09-27 05:35:06 +01:00
|
|
|
if (error) {
|
2024-04-19 05:45:48 +01:00
|
|
|
snackbar.error('snackbar.course_settings.error.failed_deletion');
|
2023-09-27 05:35:06 +01:00
|
|
|
console.log(error);
|
|
|
|
|
} else {
|
2025-11-24 01:00:50 +01:00
|
|
|
$profile.telegramChatId = null;
|
2024-04-19 05:45:48 +01:00
|
|
|
snackbar.success('snackbar.course_settings.success.successful_deletion');
|
2023-09-26 09:01:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2025-11-21 12:18:04 +01:00
|
|
|
<Grid class="mt-5 w-full">
|
2025-11-01 15:49:29 +01:00
|
|
|
<Row class="border-bottom-c flex flex-col justify-center py-7 lg:flex-row lg:justify-start">
|
2023-09-26 11:57:31 +01:00
|
|
|
<Column sm={4} md={4} lg={4} class="flex items-center justify-center">
|
2025-11-01 15:49:29 +01:00
|
|
|
<img src="/telegram-svg.svg" alt="" class="mr-2 w-10" />
|
2024-04-19 05:45:48 +01:00
|
|
|
<SectionTitle>{$t('settings.integrations.heading')}</SectionTitle></Column
|
2023-09-26 09:01:53 +00:00
|
|
|
>
|
|
|
|
|
|
2025-11-01 15:49:29 +01:00
|
|
|
<Column sm={8} md={8} lg={8} class="mt-2 flex flex-col items-center lg:mt-0 lg:items-start">
|
2025-11-24 01:00:50 +01:00
|
|
|
{#if $profile.telegramChatId !== null}
|
2025-11-01 15:49:29 +01:00
|
|
|
<div class="flex w-full flex-col items-center">
|
2023-09-26 11:57:31 +01:00
|
|
|
<div class="flex items-center">
|
2025-11-01 15:49:29 +01:00
|
|
|
<CircleCheckIcon size={16} filled />
|
2024-04-19 05:45:48 +01:00
|
|
|
<SectionTitle>{$t('settings.integrations.success_message')}</SectionTitle>
|
2023-09-26 11:57:31 +01:00
|
|
|
</div>
|
2023-09-26 09:01:53 +00:00
|
|
|
<PrimaryButton className="mt-3" variant={VARIANTS.CONTAINED_DANGER} onClick={deleteChatId}
|
2024-04-19 05:45:48 +01:00
|
|
|
>{$t('settings.integrations.disconnect')}</PrimaryButton
|
2023-09-26 09:01:53 +00:00
|
|
|
>
|
|
|
|
|
</div>
|
|
|
|
|
{:else}
|
|
|
|
|
<div>
|
2025-11-01 15:49:29 +01:00
|
|
|
<h3 class="text-lg font-normal">
|
2024-04-19 05:45:48 +01:00
|
|
|
{$t('settings.integrations.sub_heading')}
|
2023-09-26 09:01:53 +00:00
|
|
|
</h3>
|
2024-04-26 17:54:11 +01:00
|
|
|
<h4 class="font-normal">{$t('settings.integrations.step_authenticate')}</h4>
|
2023-09-26 09:01:53 +00:00
|
|
|
<PrimaryButton
|
|
|
|
|
className="mb-5"
|
|
|
|
|
variant={VARIANTS.OUTLINED}
|
|
|
|
|
onClick={() => window.open('https://t.me/classroomio_bot', '_blank')}
|
2024-04-26 17:54:11 +01:00
|
|
|
><span class="mr-2">{$t('settings.integrations.open_bot_button')}</span>
|
2025-11-21 12:18:04 +01:00
|
|
|
<ArrowUpRightIcon /></PrimaryButton
|
2023-09-26 09:01:53 +00:00
|
|
|
>
|
2024-04-26 17:54:11 +01:00
|
|
|
<h4 class="font-normal">{$t('settings.integrations.step_chatId')}</h4>
|
2023-09-26 11:57:31 +01:00
|
|
|
<TextField
|
|
|
|
|
bind:value={chatId}
|
|
|
|
|
placeholder="360111"
|
|
|
|
|
className="w-full lg:w-60 mb-5"
|
|
|
|
|
type="number"
|
|
|
|
|
isRequired
|
|
|
|
|
/>
|
2025-11-01 15:49:29 +01:00
|
|
|
<PrimaryButton onClick={addChatId}>{$t('settings.integrations.connect_button')}</PrimaryButton>
|
2023-09-26 09:01:53 +00:00
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
</Column>
|
|
|
|
|
</Row>
|
|
|
|
|
</Grid>
|