e2corporation commented on code in PR #3017: URL: https://github.com/apache/incubator-devlake/pull/3017#discussion_r966592670
########## config-ui/src/pages/connections/webhook/form-modal.jsx: ########## @@ -0,0 +1,150 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +import React, { useState, useEffect, useMemo } from "react"; +import { Dialog, Button, Toaster, Position, Intent } from "@blueprintjs/core"; +import { CopyToClipboard } from "react-copy-to-clipboard"; + +import { ReactComponent as Copy } from "@/images/icons/copy.svg"; +import * as S from "./styled"; + +const CopyToaster = Toaster.create({ + position: Position.TOP_RIGHT, +}); + +export const FormModal = ({ + visible, + modalType, + record, + onCancel, + onCreate, + onUpdate, + onDelete, +}) => { + const [name, setName] = useState(""); + const [error, setError] = useState(""); + + const title = useMemo(() => { + switch (modalType) { + case "add": + return "Add a New Webhook"; + case "edit": + return "Edit Webhook"; + case "delete": + return "Delete this Webhook? "; + } + }, [modalType]); + + useEffect(() => { + setName(record?.name); + }, [record]); + + const handleInputChange = (e) => { + setName(e.target.value); + setError(""); + }; + + const handleSubmit = () => { + if (!name) { + setError("Name is required"); + return; + } + + if (modalType === "add") { + onCreate(name); + } else if (modalType === "edit") { + onUpdate(record.id, name); + } + }; + + return ( + <Dialog isOpen={visible} title={title} onClose={onCancel}> + {modalType === "delete" ? ( + <S.FormWrapper> + <div className="message"> + <p>This Webhook cannot be recovered once it’s deleted.</p> + </div> + <div className="btns"> + <Button onClick={onCancel}>Cancel</Button> + <Button intent={Intent.PRIMARY} onClick={() => onDelete(record.id)}> + Confirm + </Button> + </div> + </S.FormWrapper> + ) : ( + <S.FormWrapper> + <div className="form"> + <h2>Webhook Name *</h2> + <p> + Give your Webhook a unique name to help you identify it in the + future. + </p> + <input Review Comment: Set an inlined style of `width: 100%` so the input stretches to the width of the Modal Dialog. Although the vanilla `<input />` tag will be sufficient for now, you may want to consider using the `InputGroup` component from BlueprintJS core (see our other form inputs). `Before` <img width="547" alt="Screen Shot 2022-09-08 at 11 36 17 PM" src="https://user-images.githubusercontent.com/1742233/189266727-ceb2400f-9f82-4fb6-9a5d-d1cee1a2d8ee.png"> `After` <img width="526" alt="Screen Shot 2022-09-08 at 11 36 32 PM" src="https://user-images.githubusercontent.com/1742233/189266752-7178550a-9bc9-4b6a-aa8f-be2ad4b1e2f9.png"> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
