1- import HeaderUserCheckbox from "@components/HeaderUserCheckbox " ;
2- import { FormModal , Textarea } from "@dolthub/react-components " ;
1+ import { FormInput , FormModal , Textarea } from "@dolthub/react-components " ;
2+ import { useEffectAsync } from "@dolthub/react-hooks " ;
33import { Maybe } from "@dolthub/web-utils" ;
44import { StatusFragment } from "@gen/graphql-types" ;
55import useSqlBuilder from "@hooks/useSqlBuilder" ;
@@ -16,20 +16,50 @@ type Props = ModalProps & {
1616 status : StatusFragment [ ] ;
1717} ;
1818
19+ const isElectron = process . env . NEXT_PUBLIC_FOR_ELECTRON === "true" ;
20+
1921export default function CommitModal ( props : Props ) {
2022 const router = useRouter ( ) ;
2123 const defaultMsg = getDefaultCommitMsg ( props . params . refName , props . status ) ;
2224 const [ msg , setMsg ] = useState ( defaultMsg ) ;
25+ const [ authorName , setAuthorName ] = useState ( "" ) ;
26+ const [ authorEmail , setAuthorEmail ] = useState ( "" ) ;
2327 const userHeaders = useUserHeaders ( ) ;
24- const [ addCommitAuthor , setAddCommitAuthor ] = useState ( ! ! userHeaders ) ;
2528 const { getCallProcedure } = useSqlBuilder ( ) ;
2629
27- const onSubmit = ( e : SyntheticEvent ) => {
30+ const headerName = userHeaders ?. user ;
31+ const headerEmail = userHeaders ?. email ;
32+ const hasHeaders = ! ! headerName || ! ! headerEmail ;
33+
34+ // Load stored author for Electron, or populate from headers
35+ useEffectAsync ( async ( ) => {
36+ if ( hasHeaders ) {
37+ setAuthorName ( headerName ?? "" ) ;
38+ setAuthorEmail ( headerEmail ?? "" ) ;
39+ return ;
40+ }
41+ if ( isElectron ) {
42+ const stored = await window . ipc . getCommitAuthor ( ) ;
43+ if ( stored ) {
44+ setAuthorName ( stored . name ) ;
45+ setAuthorEmail ( stored . email ) ;
46+ }
47+ }
48+ } , [ userHeaders ] ) ;
49+
50+ const onSubmit = async ( e : SyntheticEvent ) => {
2851 e . preventDefault ( ) ;
52+ // Persist author on desktop when not using headers
53+ if ( isElectron && ! hasHeaders && authorName && authorEmail ) {
54+ await window . ipc . setCommitAuthor ( {
55+ name : authorName ,
56+ email : authorEmail ,
57+ } ) ;
58+ }
2959 const q = getCallProcedure ( "DOLT_COMMIT" , [
3060 "-Am" ,
3161 msg ,
32- ...getAuthorArgs ( userHeaders ?. user , userHeaders ?. email ) ,
62+ ...getAuthorArgs ( authorName , authorEmail ) ,
3363 ] ) ;
3464 const { href, as } = sqlQuery ( { ...props . params , q } ) ;
3565 router . push ( href , as ) . catch ( console . error ) ;
@@ -64,12 +94,40 @@ export default function CommitModal(props: Props) {
6494 required
6595 light
6696 />
67- < HeaderUserCheckbox
68- shouldAddAuthor = { addCommitAuthor }
69- setShouldAddAuthor = { setAddCommitAuthor }
70- userHeaders = { userHeaders }
71- kind = "commit"
72- />
97+ < div className = { css . authorFields } >
98+ < FormInput
99+ value = { authorName }
100+ label = "Author Name"
101+ onChangeString = { setAuthorName }
102+ placeholder = "Author Name"
103+ disabled = { hasHeaders }
104+ light
105+ />
106+ < FormInput
107+ value = { authorEmail }
108+ label = "Author Email"
109+ onChangeString = { setAuthorEmail }
110+ placeholder = "author@example.com"
111+ disabled = { hasHeaders }
112+ light
113+ />
114+ { hasHeaders && (
115+ < p className = { css . authorNote } >
116+ Author is set from request headers and cannot be edited.
117+ </ p >
118+ ) }
119+ { ! hasHeaders && ! isElectron && (
120+ < p className = { css . authorNote } >
121+ Optional. If not provided, the SQL user will be used as the commit
122+ author.
123+ </ p >
124+ ) }
125+ { ! hasHeaders && isElectron && (
126+ < p className = { css . authorNote } >
127+ Optional. Author will be saved for future commits.
128+ </ p >
129+ ) }
130+ </ div >
73131 </ div >
74132 </ FormModal >
75133 ) ;
0 commit comments