1- import { Form , useNavigation } from "@remix-run/react" ;
2- import { Button } from "~/components/primitives/Buttons" ;
1+ import { useSubmit } from "@remix-run/react" ;
32import { InputGroup } from "~/components/primitives/InputGroup" ;
43import { Label } from "~/components/primitives/Label" ;
54import { Paragraph } from "~/components/primitives/Paragraph" ;
@@ -17,54 +16,56 @@ export function SessionDurationSetting({
1716 options,
1817 orgCapSeconds,
1918} : SessionDurationSettingProps ) {
20- const navigation = useNavigation ( ) ;
21- const isSubmitting =
22- navigation . state !== "idle" &&
23- navigation . formAction === "/resources/account/session-duration" ;
19+ const submit = useSubmit ( ) ;
2420
2521 const orgCapOption =
2622 orgCapSeconds === null ? null : options . find ( ( o ) => o . value === orgCapSeconds ) ;
2723
2824 return (
29- < Form method = "post" action = "/resources/account/session-duration" className = "w-full" >
30- < InputGroup className = "mb-4" >
31- < Label > Automatic logout</ Label >
32- < Paragraph variant = "small" >
33- Automatically log out after this period of time. Choose a shorter duration for added
34- security on shared or unattended devices.
35- { orgCapSeconds !== null ? (
36- < >
37- { " " }
38- Your organization caps this at { orgCapOption ?. label ?? `${ orgCapSeconds } seconds` } .
39- </ >
40- ) : null }
41- </ Paragraph >
42- </ InputGroup >
43- < div className = "flex items-center gap-2" >
44- < Select
45- name = "sessionDuration"
46- variant = "tertiary/medium"
47- defaultValue = { String ( currentValue ) }
48- text = { ( value : string ) =>
49- options . find ( ( o ) => String ( o . value ) === value ) ?. label ?? "Select a duration"
50- }
51- dropdownIcon
52- >
53- { options . map ( ( option ) => (
54- < SelectItem key = { option . value } value = { String ( option . value ) } >
55- { option . label }
56- </ SelectItem >
57- ) ) }
58- </ Select >
59- < Button
60- type = "submit"
61- variant = "primary/medium"
62- disabled = { isSubmitting }
63- data-action = "save session duration"
64- >
65- { isSubmitting ? "Saving…" : "Save" }
66- </ Button >
25+ < div className = "w-full" >
26+ < div className = "flex w-full items-center justify-between gap-4" >
27+ < InputGroup className = "flex-1" >
28+ < Label > Automatic logout</ Label >
29+ < Paragraph variant = "small" >
30+ Automatically log out after a period of time.
31+ { orgCapSeconds !== null ? (
32+ < >
33+ { " " }
34+ Your organization caps this at { orgCapOption ?. label ?? `${ orgCapSeconds } seconds` } .
35+ </ >
36+ ) : null }
37+ </ Paragraph >
38+ </ InputGroup >
39+ < div className = "flex flex-none items-center" >
40+ < Select
41+ name = "sessionDuration"
42+ variant = "secondary/small"
43+ defaultValue = { String ( currentValue ) }
44+ setValue = { ( value ) => {
45+ const next = Array . isArray ( value ) ? value [ 0 ] : value ;
46+ if ( typeof next !== "string" || next === String ( currentValue ) ) return ;
47+ submit (
48+ { sessionDuration : next } ,
49+ { method : "post" , action : "/resources/account/session-duration" }
50+ ) ;
51+ } }
52+ text = { ( value : string ) =>
53+ options . find ( ( o ) => String ( o . value ) === value ) ?. label ?? "Select a duration"
54+ }
55+ dropdownIcon
56+ >
57+ { options . map ( ( option ) => (
58+ < SelectItem
59+ key = { option . value }
60+ value = { String ( option . value ) }
61+ className = "text-text-bright"
62+ >
63+ { option . label }
64+ </ SelectItem >
65+ ) ) }
66+ </ Select >
67+ </ div >
6768 </ div >
68- </ Form >
69+ </ div >
6970 ) ;
7071}
0 commit comments