Skip to content

Commit af485b9

Browse files
authored
Fix custom oauth client (#872)
* A checkbox can now be readonly and not be checkable, with correct styling * Use readOnly for the hasCustomClient checkbox, not disabled * Better styling of the disabled state * The update oauth form too
1 parent a739eba commit af485b9

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

apps/webapp/app/components/integrations/ConnectToOAuthForm.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,17 @@ export function ConnectToOAuthForm({
127127
id="hasCustomClient"
128128
label="Use my OAuth App"
129129
variant="simple/small"
130-
disabled={requiresCustomOAuthApp}
130+
readOnly={requiresCustomOAuthApp}
131131
onChange={(checked) => setUseMyOAuthApp(checked)}
132132
{...conform.input(hasCustomClient, { type: "checkbox" })}
133133
defaultChecked={requiresCustomOAuthApp}
134134
/>
135135
{useMyOAuthApp && (
136136
<div className="ml-6 mt-2">
137137
<Paragraph variant="small" className="mb-2">
138-
Set the callback url to <CodeBlock code={callbackUrl} showLineNumbers={false} />
138+
Set the callback url to
139139
</Paragraph>
140+
<CodeBlock code={callbackUrl} showLineNumbers={false} />
140141
<div className="flex flex-col gap-2">
141142
<div className="flex gap-2">
142143
<InputGroup fullWidth>

apps/webapp/app/components/integrations/UpdateOAuthForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export function UpdateOAuthForm({
117117
id="hasCustomClient"
118118
label="Use my OAuth App"
119119
variant="simple/small"
120-
disabled={requiresCustomOAuthApp}
120+
readOnly={requiresCustomOAuthApp}
121121
onChange={(checked) => setUseMyOAuthApp(checked)}
122122
{...conform.input(hasCustomClient, { type: "checkbox" })}
123123
defaultChecked={requiresCustomOAuthApp}

apps/webapp/app/components/primitives/Checkbox.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,16 @@ export const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
109109
return (
110110
<div
111111
className={cn(
112-
"group flex cursor-pointer items-start gap-x-2 transition",
112+
"group flex items-start gap-x-2 transition ",
113+
props.readOnly || disabled ? "cursor-default" : "cursor-pointer",
113114
buttonClassName,
114115
isChecked && isCheckedClassName,
115-
isDisabled && isDisabledClassName,
116+
(isDisabled || props.readOnly) && isDisabledClassName,
116117
className
117118
)}
118119
onClick={(e) => {
119-
if (isDisabled) return;
120+
//returning false is not setting the state to false, it stops the event from bubbling up
121+
if (isDisabled || props.readOnly === true) return false;
120122
setIsChecked((c) => !c);
121123
}}
122124
>
@@ -127,12 +129,15 @@ export const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
127129
value={value}
128130
checked={isChecked}
129131
onChange={(e) => {
132+
//returning false is not setting the state to false, it stops the event from bubbling up
133+
if (isDisabled || props.readOnly === true) return false;
130134
setIsChecked(!isChecked);
131135
}}
132136
disabled={isDisabled}
133137
className={cn(
134138
inputPositionClasses,
135-
"cursor-pointer rounded-sm border border-slate-700 bg-transparent transition checked:!bg-indigo-500 group-hover:bg-slate-900 group-hover:checked:bg-indigo-500 group-focus:ring-1 focus:ring-indigo-500 focus:ring-offset-0 focus:ring-offset-transparent focus-visible:outline-none focus-visible:ring-indigo-500 disabled:border-slate-650 disabled:!bg-slate-700"
139+
props.readOnly || disabled ? "cursor-default" : "cursor-pointer",
140+
"rounded-sm border border-slate-700 bg-transparent transition checked:!bg-indigo-500 read-only:border-slate-650 read-only:!bg-slate-700 group-hover:bg-slate-900 group-hover:checked:bg-indigo-500 group-focus:ring-1 focus:ring-indigo-500 focus:ring-offset-0 focus:ring-offset-transparent focus-visible:outline-none focus-visible:ring-indigo-500 disabled:border-slate-650 disabled:!bg-slate-700"
136141
)}
137142
id={id}
138143
ref={ref}
@@ -141,7 +146,10 @@ export const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
141146
<div className="flex items-center gap-x-2">
142147
<label
143148
htmlFor={id}
144-
className={cn("cursor-pointer", labelClassName)}
149+
className={cn(
150+
props.readOnly || disabled ? "cursor-default" : "cursor-pointer",
151+
labelClassName
152+
)}
145153
onClick={(e) => e.preventDefault()}
146154
>
147155
{label}

0 commit comments

Comments
 (0)