Skip to content
Snippets Groups Projects
Commit 191f8200 authored by Guilhem CARRON's avatar Guilhem CARRON
Browse files

Add deletion modal

parent 9b7a5f05
No related branches found
No related tags found
2 merge requests!7feat: add front office,!2Feat/setup auth
...@@ -8,6 +8,9 @@ import Poll from '../Poll/Poll' ...@@ -8,6 +8,9 @@ import Poll from '../Poll/Poll'
import MonthlyNews from '../MonthlyNews/MonthlyNews' import MonthlyNews from '../MonthlyNews/MonthlyNews'
import { IPoll } from '../../models/poll.model' import { IPoll } from '../../models/poll.model'
import Loader from '../Loader/Loader' import Loader from '../Loader/Loader'
import Modal from '../Modal/Modal'
export type ContentItems = 'poll' | 'monthlyNews' | ''
const Editing: React.FC = () => { const Editing: React.FC = () => {
const [date, setDate] = useState<Date>(new Date()) const [date, setDate] = useState<Date>(new Date())
...@@ -18,6 +21,8 @@ const Editing: React.FC = () => { ...@@ -18,6 +21,8 @@ const Editing: React.FC = () => {
const [isTouched, setIsTouched] = useState<boolean>(false) const [isTouched, setIsTouched] = useState<boolean>(false)
const [refreshData, setRefreshData] = useState(false) const [refreshData, setRefreshData] = useState(false)
const [isLoading, setisLoading] = useState<boolean>(false) const [isLoading, setisLoading] = useState<boolean>(false)
const [warningModal, setwarningModal] = useState<boolean>(false)
const [toDelete, settoDelete] = useState<ContentItems>('')
const { user }: Partial<UserContextProps> = useContext(UserContext) const { user }: Partial<UserContextProps> = useContext(UserContext)
const monthlyNewsService = new MonthlyNewsService() const monthlyNewsService = new MonthlyNewsService()
...@@ -63,6 +68,19 @@ const Editing: React.FC = () => { ...@@ -63,6 +68,19 @@ const Editing: React.FC = () => {
setRefreshData(true) setRefreshData(true)
} }
} }
const handleOpenDeleteModal = (target: ContentItems) => {
settoDelete(target)
setwarningModal(true)
}
const handleConfirmAlert = () => {
if (toDelete === 'monthlyNews') {
handleDeleteMonthlyNews()
}
if (toDelete === 'poll') {
handleDeletePoll()
}
setwarningModal(false)
}
const isEmpty = (): boolean => { const isEmpty = (): boolean => {
if ((quote !== '' || header !== '') && isTouched) { if ((quote !== '' || header !== '') && isTouched) {
...@@ -154,7 +172,7 @@ const Editing: React.FC = () => { ...@@ -154,7 +172,7 @@ const Editing: React.FC = () => {
onSave={handleSaveMonthlyNews} onSave={handleSaveMonthlyNews}
onCancel={handleCancel} onCancel={handleCancel}
handleChange={handleEditorChange} handleChange={handleEditorChange}
onDelete={handleDeleteMonthlyNews} onDelete={handleOpenDeleteModal}
/> />
<hr /> <hr />
<Poll <Poll
...@@ -163,10 +181,31 @@ const Editing: React.FC = () => { ...@@ -163,10 +181,31 @@ const Editing: React.FC = () => {
handleChange={handleEditorChange} handleChange={handleEditorChange}
onSave={handleSavePoll} onSave={handleSavePoll}
onCancel={handleCancel} onCancel={handleCancel}
onDelete={handleDeletePoll} onDelete={handleOpenDeleteModal}
/> />
</div> </div>
)} )}
{warningModal && (
<Modal>
<>
<div className="modal-text">
Etes-vous sûr de vouloir supprimer{' '}
{toDelete === 'poll' ? 'ce sondage' : 'cette news mensuelle'} ?
</div>
<div className="buttons">
<button
className="btnCancel"
onClick={() => setwarningModal(false)}
>
Annuler
</button>
<button className="btnValid" onClick={handleConfirmAlert}>
Continuer
</button>
</div>
</>
</Modal>
)}
</> </>
) )
} }
......
import { Editor } from '@tinymce/tinymce-react' import { Editor } from '@tinymce/tinymce-react'
import React from 'react' import React from 'react'
import { ContentItems } from '../Editing/Editing'
interface MonthlyNewsProps { interface MonthlyNewsProps {
onSave: () => Promise<void> onSave: () => Promise<void>
...@@ -10,7 +11,7 @@ interface MonthlyNewsProps { ...@@ -10,7 +11,7 @@ interface MonthlyNewsProps {
value: string, value: string,
type: 'header' | 'quote' | 'question' | 'link' type: 'header' | 'quote' | 'question' | 'link'
) => void ) => void
onDelete: () => Promise<void> onDelete: (target: ContentItems) => void
} }
const MonthlyNews: React.FC<MonthlyNewsProps> = ({ const MonthlyNews: React.FC<MonthlyNewsProps> = ({
onSave, onSave,
...@@ -110,7 +111,7 @@ const MonthlyNews: React.FC<MonthlyNewsProps> = ({ ...@@ -110,7 +111,7 @@ const MonthlyNews: React.FC<MonthlyNewsProps> = ({
<button className="btnValid" onClick={onSave}> <button className="btnValid" onClick={onSave}>
Sauvegarder Sauvegarder
</button> </button>
<button className="btnDelete" onClick={onDelete}> <button className="btnDelete" onClick={() => onDelete('monthlyNews')}>
Supprimer Supprimer
</button> </button>
</div> </div>
......
import { Editor } from '@tinymce/tinymce-react' import { Editor } from '@tinymce/tinymce-react'
import React, { ChangeEvent } from 'react' import React, { ChangeEvent } from 'react'
import { ContentItems } from '../Editing/Editing'
import './poll.scss' import './poll.scss'
interface PollProps { interface PollProps {
...@@ -11,7 +12,7 @@ interface PollProps { ...@@ -11,7 +12,7 @@ interface PollProps {
) => void ) => void
onSave: () => Promise<void> onSave: () => Promise<void>
onCancel: () => void onCancel: () => void
onDelete: () => Promise<void> onDelete: (target: ContentItems) => void
} }
const Poll: React.FC<PollProps> = ({ const Poll: React.FC<PollProps> = ({
question, question,
...@@ -57,7 +58,7 @@ const Poll: React.FC<PollProps> = ({ ...@@ -57,7 +58,7 @@ const Poll: React.FC<PollProps> = ({
<button className="btnValid" onClick={onSave}> <button className="btnValid" onClick={onSave}>
Sauvegarder Sauvegarder
</button> </button>
<button className="btnDelete" onClick={onDelete}> <button className="btnDelete" onClick={() => onDelete('poll')}>
Supprimer Supprimer
</button> </button>
</div> </div>
......
import React, { useContext, useState } from 'react' import React, { useState } from 'react'
import axios from 'axios' import axios from 'axios'
import { User } from '../models/user.model' import { User } from '../models/user.model'
import { UserContext } from './userContext'
const _apiUrl: string = 'https://localhost:1443/' const _apiUrl: string = 'https://localhost:1443/'
...@@ -14,7 +13,7 @@ export interface Auth { ...@@ -14,7 +13,7 @@ export interface Auth {
} }
export const useAuth = (): Auth => { export const useAuth = (): Auth => {
const [error, setError] = useState(null) const [error, setError] = useState(null)
const { setisLogged } = useContext(UserContext)
//login user //login user
const loginUser = async (): Promise<void> => { const loginUser = async (): Promise<void> => {
try { try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment