mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-18 13:15:27 +00:00
chore: update dialogs
This commit is contained in:
parent
4c099e7699
commit
c51501dc0a
@ -10,40 +10,70 @@ interface Props extends DialogProps {
|
|||||||
shortcutId?: ShortcutId;
|
shortcutId?: ShortcutId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface State {
|
||||||
|
shortcutCreate: ShortcutCreate;
|
||||||
|
}
|
||||||
|
|
||||||
const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
|
const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
|
||||||
const { destroy, workspaceId, shortcutId } = props;
|
const { destroy, workspaceId, shortcutId } = props;
|
||||||
const [name, setName] = useState<string>("");
|
const [state, setState] = useState<State>({
|
||||||
const [link, setLink] = useState<string>("");
|
shortcutCreate: {
|
||||||
const [visibility, setVisibility] = useState<Visibility>("PRIVATE");
|
workspaceId: workspaceId,
|
||||||
|
name: "",
|
||||||
|
link: "",
|
||||||
|
description: "",
|
||||||
|
visibility: "PRIVATE",
|
||||||
|
},
|
||||||
|
});
|
||||||
const requestState = useLoading(false);
|
const requestState = useLoading(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (shortcutId) {
|
if (shortcutId) {
|
||||||
const shortcutTemp = shortcutService.getShortcutById(shortcutId);
|
const shortcutTemp = shortcutService.getShortcutById(shortcutId);
|
||||||
if (shortcutTemp) {
|
if (shortcutTemp) {
|
||||||
setName(shortcutTemp.name);
|
setState({
|
||||||
setLink(shortcutTemp.link);
|
...state,
|
||||||
|
shortcutCreate: Object.assign(state.shortcutCreate, {
|
||||||
|
workspaceId: shortcutTemp.workspaceId,
|
||||||
|
name: shortcutTemp.name,
|
||||||
|
link: shortcutTemp.link,
|
||||||
|
description: shortcutTemp.description,
|
||||||
|
visibility: shortcutTemp.visibility,
|
||||||
|
}),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [shortcutId]);
|
}, [shortcutId]);
|
||||||
|
|
||||||
const handleNameInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>, key: string) => {
|
||||||
const text = e.target.value as string;
|
const text = e.target.value as string;
|
||||||
setName(text);
|
const tempObject = {} as any;
|
||||||
|
tempObject[key] = text;
|
||||||
|
|
||||||
|
setState({
|
||||||
|
...state,
|
||||||
|
shortcutCreate: Object.assign(state.shortcutCreate, tempObject),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleNameInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
handleInputChange(e, "name");
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleLinkInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleLinkInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const text = e.target.value as string;
|
handleInputChange(e, "link");
|
||||||
setLink(text);
|
};
|
||||||
|
|
||||||
|
const handleDescriptionInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
handleInputChange(e, "description");
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleVisibilityInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleVisibilityInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const text = e.target.value as string;
|
handleInputChange(e, "visibility");
|
||||||
setVisibility(text as Visibility);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSaveBtnClick = async () => {
|
const handleSaveBtnClick = async () => {
|
||||||
if (!name) {
|
if (!state.shortcutCreate.name) {
|
||||||
toastHelper.error("Name is required");
|
toastHelper.error("Name is required");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -52,16 +82,13 @@ const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
|
|||||||
if (shortcutId) {
|
if (shortcutId) {
|
||||||
await shortcutService.patchShortcut({
|
await shortcutService.patchShortcut({
|
||||||
id: shortcutId,
|
id: shortcutId,
|
||||||
name,
|
name: state.shortcutCreate.name,
|
||||||
link,
|
link: state.shortcutCreate.link,
|
||||||
|
description: state.shortcutCreate.description,
|
||||||
|
visibility: state.shortcutCreate.visibility,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await shortcutService.createShortcut({
|
await shortcutService.createShortcut(state.shortcutCreate);
|
||||||
workspaceId,
|
|
||||||
name,
|
|
||||||
link,
|
|
||||||
visibility: "PRIVATE",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@ -81,11 +108,33 @@ const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
|
|||||||
<div className="w-full flex flex-col justify-start items-start">
|
<div className="w-full flex flex-col justify-start items-start">
|
||||||
<div className="w-full flex flex-col justify-start items-start mb-3">
|
<div className="w-full flex flex-col justify-start items-start mb-3">
|
||||||
<span className="mb-2">Name</span>
|
<span className="mb-2">Name</span>
|
||||||
<input className="w-full rounded border px-2 py-2" type="text" value={name} onChange={handleNameInputChange} />
|
<input
|
||||||
|
className="w-full rounded border shadow-inner text-sm px-2 py-2"
|
||||||
|
type="text"
|
||||||
|
placeholder="shortcut-name"
|
||||||
|
value={state.shortcutCreate.name}
|
||||||
|
onChange={handleNameInputChange}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full flex flex-col justify-start items-start mb-3">
|
<div className="w-full flex flex-col justify-start items-start mb-3">
|
||||||
<span className="mb-2">Link</span>
|
<span className="mb-2">Link</span>
|
||||||
<input className="w-full rounded border px-2 py-2" type="text" value={link} onChange={handleLinkInputChange} />
|
<input
|
||||||
|
className="w-full rounded border shadow-inner text-sm px-2 py-2"
|
||||||
|
type="text"
|
||||||
|
placeholder="The full URL of the page you want to get to"
|
||||||
|
value={state.shortcutCreate.link}
|
||||||
|
onChange={handleLinkInputChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="w-full flex flex-col justify-start items-start mb-3">
|
||||||
|
<span className="mb-2">Description</span>
|
||||||
|
<input
|
||||||
|
className="w-full rounded border shadow-inner text-sm px-2 py-2"
|
||||||
|
type="text"
|
||||||
|
placeholder="Something to describe the link"
|
||||||
|
value={state.shortcutCreate.description}
|
||||||
|
onChange={handleDescriptionInputChange}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full flex flex-col justify-start items-start mb-3">
|
<div className="w-full flex flex-col justify-start items-start mb-3">
|
||||||
<span className="mb-2">Visibility</span>
|
<span className="mb-2">Visibility</span>
|
||||||
@ -96,7 +145,7 @@ const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
|
|||||||
id="visibility-private"
|
id="visibility-private"
|
||||||
value="PRIVATE"
|
value="PRIVATE"
|
||||||
onChange={handleVisibilityInputChange}
|
onChange={handleVisibilityInputChange}
|
||||||
checked={visibility === "PRIVATE"}
|
checked={state.shortcutCreate.visibility === "PRIVATE"}
|
||||||
/>
|
/>
|
||||||
<label htmlFor="visibility-private" className="ml-1 mr-4">
|
<label htmlFor="visibility-private" className="ml-1 mr-4">
|
||||||
Only for myself
|
Only for myself
|
||||||
@ -107,7 +156,7 @@ const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
|
|||||||
id="visibility-workspace"
|
id="visibility-workspace"
|
||||||
value="WORKSPACE"
|
value="WORKSPACE"
|
||||||
onChange={handleVisibilityInputChange}
|
onChange={handleVisibilityInputChange}
|
||||||
checked={visibility === "WORKSPACE"}
|
checked={state.shortcutCreate.visibility === "WORKSPACE"}
|
||||||
/>
|
/>
|
||||||
<label htmlFor="visibility-workspace" className="ml-1">
|
<label htmlFor="visibility-workspace" className="ml-1">
|
||||||
Public in workspace
|
Public in workspace
|
||||||
@ -116,9 +165,7 @@ const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
|
|||||||
</div>
|
</div>
|
||||||
<div className="w-full flex flex-row justify-end items-center">
|
<div className="w-full flex flex-row justify-end items-center">
|
||||||
<button
|
<button
|
||||||
className={`border rounded px-3 py-2 border-green-600 bg-green-600 text-white hover:bg-green-700 ${
|
className={`rounded px-3 py-2 shadow bg-green-600 text-white hover:bg-green-700 ${requestState.isLoading ? "opacity-80" : ""}`}
|
||||||
requestState.isLoading ? "opacity-80" : ""
|
|
||||||
}`}
|
|
||||||
onClick={handleSaveBtnClick}
|
onClick={handleSaveBtnClick}
|
||||||
>
|
>
|
||||||
Save
|
Save
|
||||||
|
@ -9,34 +9,56 @@ interface Props extends DialogProps {
|
|||||||
workspaceId?: WorkspaceId;
|
workspaceId?: WorkspaceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface State {
|
||||||
|
workspaceCreate: WorkspaceCreate;
|
||||||
|
}
|
||||||
|
|
||||||
const CreateWorkspaceDialog: React.FC<Props> = (props: Props) => {
|
const CreateWorkspaceDialog: React.FC<Props> = (props: Props) => {
|
||||||
const { destroy, workspaceId } = props;
|
const { destroy, workspaceId } = props;
|
||||||
const [name, setName] = useState<string>("");
|
const [state, setState] = useState<State>({
|
||||||
const [description, setDescription] = useState<string>("");
|
workspaceCreate: {
|
||||||
|
name: "",
|
||||||
|
description: "",
|
||||||
|
},
|
||||||
|
});
|
||||||
const requestState = useLoading(false);
|
const requestState = useLoading(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (workspaceId) {
|
if (workspaceId) {
|
||||||
const workspaceTemp = workspaceService.getWorkspaceById(workspaceId);
|
const workspaceTemp = workspaceService.getWorkspaceById(workspaceId);
|
||||||
if (workspaceTemp) {
|
if (workspaceTemp) {
|
||||||
setName(workspaceTemp.name);
|
setState({
|
||||||
setDescription(workspaceTemp.description);
|
...state,
|
||||||
|
workspaceCreate: Object.assign(state.workspaceCreate, {
|
||||||
|
name: workspaceTemp.name,
|
||||||
|
description: workspaceTemp.description,
|
||||||
|
}),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [workspaceId]);
|
}, [workspaceId]);
|
||||||
|
|
||||||
const handleNameInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>, key: string) => {
|
||||||
const text = e.target.value as string;
|
const text = e.target.value as string;
|
||||||
setName(text);
|
const tempObject = {} as any;
|
||||||
|
tempObject[key] = text;
|
||||||
|
|
||||||
|
setState({
|
||||||
|
...state,
|
||||||
|
workspaceCreate: Object.assign(state.workspaceCreate, tempObject),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleNameInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
handleInputChange(e, "name");
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDescriptionInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleDescriptionInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const text = e.target.value as string;
|
handleInputChange(e, "description");
|
||||||
setDescription(text);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSaveBtnClick = async () => {
|
const handleSaveBtnClick = async () => {
|
||||||
if (!name) {
|
if (!state.workspaceCreate.name) {
|
||||||
toastHelper.error("Name is required");
|
toastHelper.error("Name is required");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -45,13 +67,11 @@ const CreateWorkspaceDialog: React.FC<Props> = (props: Props) => {
|
|||||||
if (workspaceId) {
|
if (workspaceId) {
|
||||||
await workspaceService.patchWorkspace({
|
await workspaceService.patchWorkspace({
|
||||||
id: workspaceId,
|
id: workspaceId,
|
||||||
name,
|
...state.workspaceCreate,
|
||||||
description,
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await workspaceService.createWorkspace({
|
await workspaceService.createWorkspace({
|
||||||
name,
|
...state.workspaceCreate,
|
||||||
description,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@ -72,17 +92,25 @@ const CreateWorkspaceDialog: React.FC<Props> = (props: Props) => {
|
|||||||
<div className="w-full flex flex-col justify-start items-start">
|
<div className="w-full flex flex-col justify-start items-start">
|
||||||
<div className="w-full flex flex-col justify-start items-start mb-3">
|
<div className="w-full flex flex-col justify-start items-start mb-3">
|
||||||
<span className="mb-2">Name</span>
|
<span className="mb-2">Name</span>
|
||||||
<input className="w-full rounded border px-2 py-2" type="text" value={name} onChange={handleNameInputChange} />
|
<input
|
||||||
|
className="w-full rounded border text-sm shadow-inner px-2 py-2"
|
||||||
|
type="text"
|
||||||
|
value={state.workspaceCreate.name}
|
||||||
|
onChange={handleNameInputChange}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full flex flex-col justify-start items-start mb-3">
|
<div className="w-full flex flex-col justify-start items-start mb-3">
|
||||||
<span className="mb-2">Description</span>
|
<span className="mb-2">Description</span>
|
||||||
<input className="w-full rounded border px-2 py-2" type="text" value={description} onChange={handleDescriptionInputChange} />
|
<input
|
||||||
|
className="w-full rounded border text-sm shadow-inner px-2 py-2"
|
||||||
|
type="text"
|
||||||
|
value={state.workspaceCreate.description}
|
||||||
|
onChange={handleDescriptionInputChange}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full flex flex-row justify-end items-center">
|
<div className="w-full flex flex-row justify-end items-center">
|
||||||
<button
|
<button
|
||||||
className={`border rounded px-3 py-2 border-green-600 bg-green-600 text-white hover:bg-green-700 ${
|
className={`rounded px-3 py-2 shadow bg-green-600 text-white hover:bg-green-700 ${requestState.isLoading ? "opacity-80" : ""}`}
|
||||||
requestState.isLoading ? "opacity-80" : ""
|
|
||||||
}`}
|
|
||||||
onClick={handleSaveBtnClick}
|
onClick={handleSaveBtnClick}
|
||||||
>
|
>
|
||||||
Save
|
Save
|
||||||
|
3
web/src/types/modules/shortcut.d.ts
vendored
3
web/src/types/modules/shortcut.d.ts
vendored
@ -13,6 +13,7 @@ interface Shortcut {
|
|||||||
|
|
||||||
name: string;
|
name: string;
|
||||||
link: string;
|
link: string;
|
||||||
|
description: string;
|
||||||
visibility: Visibility;
|
visibility: Visibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,6 +22,7 @@ interface ShortcutCreate {
|
|||||||
|
|
||||||
name: string;
|
name: string;
|
||||||
link: string;
|
link: string;
|
||||||
|
description: string;
|
||||||
visibility: Visibility;
|
visibility: Visibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,6 +31,7 @@ interface ShortcutPatch {
|
|||||||
|
|
||||||
name?: string;
|
name?: string;
|
||||||
link?: string;
|
link?: string;
|
||||||
|
description?: string;
|
||||||
visibility?: Visibility;
|
visibility?: Visibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user