-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add simple ui to delete projects on frontend (#1314)
* feat: add simple ui to delete projects on frontend * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
02f83c3
commit 2202329
Showing
7 changed files
with
107 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/frontend/src/components/ManageProject/DeleteTab/ProjectDeleteTab.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { useState } from 'react'; | ||
import Button from '@/components/common/Button'; | ||
import { Modal } from '@/components/common/Modal'; | ||
import CoreModules from '@/shared/CoreModules'; | ||
import { DeleteProjectService } from '@/api/CreateProjectService'; | ||
|
||
const FormUpdateTab = ({ projectId, projectName }) => { | ||
const dispatch = CoreModules.useAppDispatch(); | ||
const [showModal, setShowModal] = useState(false); | ||
const [confirmProjectName, setConfirmProjectName] = useState(''); | ||
const [confirmEnabled, setConfirmEnabled] = useState(false); | ||
|
||
const onDelete = () => { | ||
setShowModal(true); | ||
}; | ||
|
||
const onSave = () => { | ||
if (confirmProjectName === projectName) { | ||
dispatch(DeleteProjectService(`${import.meta.env.VITE_API_URL}/projects/${projectId}`)); | ||
setShowModal(false); | ||
} | ||
}; | ||
|
||
const closeModal = () => { | ||
setShowModal(false); | ||
setConfirmProjectName(''); | ||
setConfirmEnabled(false); | ||
}; | ||
|
||
const handleConfirmChange = (e) => { | ||
const inputText = e.target.value; | ||
setConfirmProjectName(inputText); | ||
setConfirmEnabled(inputText === projectName); | ||
}; | ||
|
||
return ( | ||
<div className="fmtm-flex fmtm-flex-col fmtm-items-center fmtm-gap-10"> | ||
<div className="fmtm-flex fmtm-justify-left"> | ||
<Button onClick={onDelete} btnText="DELETE PROJECT" btnType="primary" className="fmtm-rounded-md" /> | ||
</div> | ||
<Modal | ||
className="fmtm-w-[700px]" | ||
description={ | ||
<div className="text-center"> | ||
<h2>Are you sure?</h2> | ||
<p>Please confirm the project name to proceed:</p> | ||
<input type="text" value={confirmProjectName} onChange={handleConfirmChange} /> | ||
<div className="fmtm-flex fmtm-justify-center fmtm-gap-4"> | ||
<Button onClick={onSave} btnText="Confirm" btnType="primary" disabled={!confirmEnabled} /> | ||
<Button onClick={closeModal} btnText="Cancel" btnType="secondary" /> | ||
</div> | ||
</div> | ||
} | ||
open={showModal} | ||
onOpenChange={setShowModal} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default FormUpdateTab; |
12 changes: 12 additions & 0 deletions
12
src/frontend/src/components/ManageProject/DeleteTab/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
import ProjectDeleteTab from './ProjectDeleteTab'; | ||
|
||
const EditTab = ({ projectId, projectName }) => { | ||
return ( | ||
<div className="fmtm-max-w-[29.5rem]"> | ||
<ProjectDeleteTab projectId={projectId} projectName={projectName} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default EditTab; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,26 @@ | ||
export function setCookie(name: string, value:string) { | ||
document.cookie = `${name}=${value}; Path=/;`; | ||
} | ||
|
||
// export function removeCookie(name, domain = '') { | ||
// document.cookie = `${name}=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT; domain=${domain}`; | ||
// } | ||
|
||
export function removeCookie(name:string) { | ||
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:01 GMT"`; | ||
} | ||
|
||
export default function getCookie(name:string) { | ||
let cookieValue:string|null = null; | ||
if (document.cookie && document.cookie !== '') { | ||
const cookies = document.cookie.split(';'); | ||
for (let i = 0; i < cookies.length; i += 1) { | ||
const cookie = cookies[i].toString().replace(/^([\s]*)|([\s]*)$/g, ''); | ||
if (cookie.substring(0, name.length + 1) === `${name}=`) { | ||
cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); | ||
break; | ||
} | ||
export function setCookie(name: string, value: string) { | ||
document.cookie = `${name}=${value}; Path=/;`; | ||
} | ||
|
||
// export function removeCookie(name, domain = '') { | ||
// document.cookie = `${name}=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT; domain=${domain}`; | ||
// } | ||
|
||
export function removeCookie(name: string) { | ||
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:01 GMT"`; | ||
} | ||
|
||
export default function getCookie(name: string) { | ||
let cookieValue: string | null = null; | ||
if (document.cookie && document.cookie !== '') { | ||
const cookies = document.cookie.split(';'); | ||
for (let i = 0; i < cookies.length; i += 1) { | ||
const cookie = cookies[i].toString().replace(/^([\s]*)|([\s]*)$/g, ''); | ||
if (cookie.substring(0, name.length + 1) === `${name}=`) { | ||
cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); | ||
break; | ||
} | ||
} | ||
return cookieValue; | ||
} | ||
|
||
return cookieValue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters