'use client' import React, { useState } from 'react' import { Form, Formik } from 'formik' import * as Yup from 'yup' import { updateOrganization, } from '@services/settings/org' import { revalidateTags } from '@services/utils/ts/requests' import { useRouter } from 'next/navigation' import { useOrg } from '@components/Contexts/OrgContext' import { useLHSession } from '@components/Contexts/LHSessionContext' import { toast } from 'react-hot-toast' import { Input } from "@components/ui/input" import { Textarea } from "@components/ui/textarea" import { Button } from "@components/ui/button" import { Label } from "@components/ui/label" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@components/ui/select" import { Switch } from "@components/ui/switch" import { mutate } from 'swr' import { getAPIUrl } from '@services/config/config' import Image from 'next/image' import learnhouseIcon from '@public/learnhouse_logo.png' const ORG_LABELS = [ { value: 'languages', label: '🌐 Languages' }, { value: 'business', label: '💰 Business' }, { value: 'ecommerce', label: '🛍 E-commerce' }, { value: 'gaming', label: '🎮 Gaming' }, { value: 'music', label: '🎸 Music' }, { value: 'sports', label: '⚽ Sports' }, { value: 'cars', label: '🚗 Cars' }, { value: 'sales_marketing', label: '🚀 Sales & Marketing' }, { value: 'tech', label: '💻 Tech' }, { value: 'photo_video', label: '📸 Photo & Video' }, { value: 'pets', label: '🐕 Pets' }, { value: 'personal_development', label: '📚 Personal Development' }, { value: 'real_estate', label: '🏠 Real Estate' }, { value: 'beauty_fashion', label: '👠 Beauty & Fashion' }, { value: 'travel', label: '✈️ Travel' }, { value: 'productivity', label: '⏳ Productivity' }, { value: 'health_fitness', label: '🍎 Health & Fitness' }, { value: 'finance', label: '📈 Finance' }, { value: 'arts_crafts', label: '🎨 Arts & Crafts' }, { value: 'education', label: '📚 Education' }, { value: 'stem', label: '🔬 STEM' }, { value: 'humanities', label: '📖 Humanities' }, { value: 'professional_skills', label: '💼 Professional Skills' }, { value: 'digital_skills', label: '💻 Digital Skills' }, { value: 'creative_arts', label: '🎨 Creative Arts' }, { value: 'social_sciences', label: '🌍 Social Sciences' }, { value: 'test_prep', label: '✍️ Test Preparation' }, { value: 'vocational', label: '🔧 Vocational Training' }, { value: 'early_education', label: '🎯 Early Education' }, ] as const const validationSchema = Yup.object().shape({ name: Yup.string() .required('Name is required') .max(60, 'Organization name must be 60 characters or less'), description: Yup.string() .required('Short description is required') .max(100, 'Short description must be 100 characters or less'), about: Yup.string() .optional() .max(400, 'About text must be 400 characters or less'), label: Yup.string().required('Organization label is required'), explore: Yup.boolean(), }) interface OrganizationValues { name: string description: string about: string label: string explore: boolean } const OrgEditGeneral: React.FC = () => { const router = useRouter() const session = useLHSession() as any const access_token = session?.data?.tokens?.access_token const org = useOrg() as any const initialValues: OrganizationValues = { name: org?.name, description: org?.description || '', about: org?.about || '', label: org?.label || '', explore: org?.explore ?? true, } const updateOrg = async (values: OrganizationValues) => { const loadingToast = toast.loading('Updating organization...') try { await updateOrganization(org.id, values, access_token) await revalidateTags(['organizations'], org.slug) mutate(`${getAPIUrl()}orgs/slug/${org.slug}`) toast.success('Organization Updated', { id: loadingToast }) } catch (err) { toast.error('Failed to update organization', { id: loadingToast }) } } return (