Skip to content

Commit b5254e8

Browse files
committed
chore: hide create form after modal closes
1 parent be632c4 commit b5254e8

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

packages/clerk-js/src/ui/components/ApiKeys/ApiKeys.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,12 @@ export const APIKeysPage = ({ subject, perPage, revokeModalRoot }: APIKeysPagePr
7979
const [selectedApiKeyName, setSelectedApiKeyName] = useState('');
8080
const [isCopyModalOpen, setIsCopyModalOpen] = useState(false);
8181

82-
const handleCreateApiKey = async (params: OnCreateParams, closeCardFn: () => void) => {
82+
const handleCreateApiKey = async (params: OnCreateParams) => {
8383
try {
8484
await createApiKey({
8585
...params,
8686
subject,
8787
});
88-
closeCardFn();
8988
card.setError(undefined);
9089
setIsCopyModalOpen(true);
9190
} catch (err: any) {
@@ -157,6 +156,15 @@ export const APIKeysPage = ({ subject, perPage, revokeModalRoot }: APIKeysPagePr
157156
</Action.Card>
158157
</Flex>
159158
</Action.Open>
159+
160+
<CopyApiKeyModal
161+
isOpen={isCopyModalOpen}
162+
onOpen={() => setIsCopyModalOpen(true)}
163+
onClose={() => setIsCopyModalOpen(false)}
164+
apiKeyName={createdApiKey?.name ?? ''}
165+
apiKeySecret={createdApiKey?.secret ?? ''}
166+
modalRoot={revokeModalRoot}
167+
/>
160168
</Action.Root>
161169

162170
<ApiKeysTable
@@ -190,14 +198,6 @@ export const APIKeysPage = ({ subject, perPage, revokeModalRoot }: APIKeysPagePr
190198
apiKeyName={selectedApiKeyName}
191199
modalRoot={revokeModalRoot}
192200
/>
193-
<CopyApiKeyModal
194-
isOpen={isCopyModalOpen}
195-
onOpen={() => setIsCopyModalOpen(true)}
196-
onClose={() => setIsCopyModalOpen(false)}
197-
apiKeyName={createdApiKey?.name ?? ''}
198-
apiKeySecret={createdApiKey?.secret ?? ''}
199-
modalRoot={revokeModalRoot}
200-
/>
201201
</Col>
202202
);
203203
};

packages/clerk-js/src/ui/components/ApiKeys/CopyApiKeyModal.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { descriptors } from '@/ui/customizables';
2+
import { useActionContext } from '@/ui/elements/Action/ActionRoot';
23
import { Card } from '@/ui/elements/Card';
34
import { ClipboardInput } from '@/ui/elements/ClipboardInput';
45
import { Form } from '@/ui/elements/Form';
@@ -35,10 +36,12 @@ export const CopyApiKeyModal = ({
3536
});
3637

3738
const { onCopy } = useClipboard(apiKeySecret);
39+
const { close: closeActionCard } = useActionContext();
3840

3941
const handleSubmit = () => {
4042
onCopy();
4143
onClose();
44+
closeActionCard();
4245
};
4346

4447
if (!isOpen) {

packages/clerk-js/src/ui/components/ApiKeys/CreateApiKeyForm.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export type OnCreateParams = {
2727
};
2828

2929
interface CreateApiKeyFormProps {
30-
onCreate: (params: OnCreateParams, closeCardFn: () => void) => void;
30+
onCreate: (params: OnCreateParams) => void;
3131
isSubmitting: boolean;
3232
}
3333

@@ -164,14 +164,11 @@ export const CreateApiKeyForm: React.FC<CreateApiKeyFormProps> = ({ onCreate, is
164164

165165
const handleSubmit = (e: React.FormEvent) => {
166166
e.preventDefault();
167-
onCreate(
168-
{
169-
name: nameField.value,
170-
description: descriptionField.value || undefined,
171-
secondsUntilExpiration: getTimeLeftInSeconds(selectedExpiration?.value),
172-
},
173-
closeCardFn,
174-
);
167+
onCreate({
168+
name: nameField.value,
169+
description: descriptionField.value || undefined,
170+
secondsUntilExpiration: getTimeLeftInSeconds(selectedExpiration?.value),
171+
});
175172
};
176173

177174
return (

0 commit comments

Comments
 (0)