1- import { useState } from 'react'
1+ import { useState , useEffect } from 'react'
22import { SlackIcon } from '@/components/icons/SlackIcon'
33import { Switch } from '@/components/ui/switch'
44import { Button } from '@/components/ui/button'
5+ import { Input } from '@/components/ui/input'
56import {
67 Dialog ,
78 DialogContent ,
89 DialogHeader ,
910 DialogTitle ,
1011} from '@/components/ui/dialog'
1112import { Tooltip , TooltipContent , TooltipTrigger } from '@/components/ui/tooltip'
12- import { useSlackStatus } from '@/api/hooks/useSlack'
13+ import { useSlackStatus , useUpdateSlackPreferences } from '@/api/hooks/useSlack'
1314import { logAndToastError } from '@/lib/utils/ebbError.util'
1415import { initiateSlackOAuth } from '@/lib/utils/slackAuth.util'
1516import { Skeleton } from '@/components/ui/skeleton'
@@ -29,7 +30,18 @@ export function SlackFocusToggle({ slackSettings, onSlackSettingsChange }: Slack
2930 const navigate = useNavigate ( )
3031
3132 const [ showDialog , setShowDialog ] = useState ( false )
33+ const [ customStatusText , setCustomStatusText ] = useState ( '' )
34+ const [ customStatusEmoji , setCustomStatusEmoji ] = useState ( '' )
3235 const { data : slackStatus , isLoading : slackStatusLoading } = useSlackStatus ( )
36+ const updatePreferencesMutation = useUpdateSlackPreferences ( )
37+
38+ // Load current preferences when dialog opens
39+ useEffect ( ( ) => {
40+ if ( showDialog && slackStatus ?. preferences ) {
41+ setCustomStatusText ( slackStatus . preferences . custom_status_text || '' )
42+ setCustomStatusEmoji ( slackStatus . preferences . custom_status_emoji || '' )
43+ }
44+ } , [ showDialog , slackStatus ?. preferences ] )
3345
3446 const handleSlackToggle = async ( ) => {
3547 if ( ! user ) {
@@ -60,6 +72,31 @@ export function SlackFocusToggle({ slackSettings, onSlackSettingsChange }: Slack
6072 }
6173 }
6274
75+ const validateEmoji = ( emoji : string ) : boolean => {
76+ if ( ! emoji ) return true // Empty is valid
77+ return emoji . startsWith ( ':' ) && emoji . endsWith ( ':' ) && emoji . length > 2
78+ }
79+
80+ const handleSavePreferences = async ( ) => {
81+ if ( ! validateEmoji ( customStatusEmoji ) ) {
82+ toast . error ( 'Emoji must be in format :emoji_name: (e.g., :brain:)' )
83+ return
84+ }
85+
86+ updatePreferencesMutation . mutate ( {
87+ custom_status_text : customStatusText ,
88+ custom_status_emoji : customStatusEmoji
89+ } , {
90+ onSuccess : ( ) => {
91+ toast . success ( 'Slack preferences updated' )
92+ setShowDialog ( false )
93+ } ,
94+ onError : ( error ) => {
95+ logAndToastError ( 'Failed to update Slack preferences' , error )
96+ }
97+ } )
98+ }
99+
63100 const navigateToSettings = ( ) => {
64101 setShowDialog ( false )
65102 // Navigate to settings page - you may need to adjust this based on your routing
@@ -128,6 +165,45 @@ export function SlackFocusToggle({ slackSettings, onSlackSettingsChange }: Slack
128165 />
129166 </ div >
130167
168+ < div className = "space-y-4" >
169+ < div className = "space-y-2" >
170+ < label htmlFor = "custom-status-text" className = "text-sm font-medium" > Custom Status Text</ label >
171+ < Input
172+ id = "custom-status-text"
173+ value = { customStatusText }
174+ onChange = { ( e ) => setCustomStatusText ( e . target . value ) }
175+ placeholder = "e.g., In a focus session"
176+ maxLength = { 100 }
177+ />
178+ < div className = "text-xs text-muted-foreground" >
179+ Status message shown during focus sessions
180+ </ div >
181+ </ div >
182+
183+ < div className = "space-y-2" >
184+ < label htmlFor = "custom-status-emoji" className = "text-sm font-medium" > Custom Status Emoji</ label >
185+ < Input
186+ id = "custom-status-emoji"
187+ value = { customStatusEmoji }
188+ onChange = { ( e ) => setCustomStatusEmoji ( e . target . value ) }
189+ placeholder = "e.g., :brain:"
190+ maxLength = { 50 }
191+ className = { ! validateEmoji ( customStatusEmoji ) ? 'border-red-500' : '' }
192+ />
193+ < div className = "text-xs text-muted-foreground" >
194+ Emoji in format :emoji_name: (e.g., :brain:, :rocket:)
195+ </ div >
196+ </ div >
197+
198+ < Button
199+ onClick = { handleSavePreferences }
200+ className = "w-full"
201+ disabled = { updatePreferencesMutation . isPending }
202+ >
203+ { updatePreferencesMutation . isPending ? 'Saving...' : 'Save Preferences' }
204+ </ Button >
205+ </ div >
206+
131207 < div className = "pt-4 border-t" >
132208 < Button
133209 variant = "outline"
0 commit comments