Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Snazzie committed Jan 31, 2024
1 parent bfd3fe2 commit 9418663
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Source/Topica.UI/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"build": "vite build",
"build:withlintcheck": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"clean": "npx rimraf node_modules"
Expand Down
34 changes: 25 additions & 9 deletions Source/Topica.UI/src/Components/CreateTopic.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
import { TopicMeta } from "@topica/client";
import { Button, Form, Input, Modal } from "antd";
import React, { useState } from "react";
import { topicsApi } from "../api/api";
import { useRequest } from "ahooks";

export const CreateTopic: React.FunctionComponent = (props) => {
export const CreateTopic: React.FunctionComponent = () => {
const [open, setOpen] = useState(false);
const [form] = Form.useForm<string>();
const [addButtonText, setAddButtonText] = useState<"Add"|"Add Another">("Add")
const {data, error, refresh: sendRequest} = useRequest(() => topicsApi.createTopic({ topicId: form.getFieldValue("id") }), {manual:true});
const [addButtonText, setAddButtonText] = useState<"Add" | "Add Another">(
"Add"
);
const {
data,
error,
refresh: sendRequest,
} = useRequest(
() => topicsApi.createTopic({ topicId: form.getFieldValue("id") }),
{ manual: true }
);
function handleClose(){
setOpen(false);
form.resetFields();
}

function handleSubmit() {
form
.validateFields({ validateOnly: true })
.then((id) => {
.then(() => {
sendRequest();
setAddButtonText("Add Another")
setAddButtonText("Add Another");
})
.catch((error) => {
});
.catch(() => {});
}
return (
<>
Expand All @@ -28,8 +40,12 @@ export const CreateTopic: React.FunctionComponent = (props) => {
open={open}
title="Create Topic"
centered
afterClose={handleClose}
closable
onCancel={handleClose}
maskClosable={true}
footer={[
<Button>Cancel</Button>,
<Button onClick={handleClose}>Cancel</Button>,
<Button type="primary" onClick={handleSubmit}>
{addButtonText}
</Button>,
Expand Down

0 comments on commit 9418663

Please sign in to comment.