Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions packages/admin-portal/src/resources/Candidate/CandidateDataForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export const CandidateDataForm: React.FC<{
const notify = useNotify()
const refresh = useRefresh()
const {globalSettings} = useContext(SettingsContext)
const [enabledDeleteImage, setEnabledDeleteImage] = useState<boolean>(true)
const getImageUrl = useGetDocumentUrl()

const [value, setValue] = useState(0)
Expand Down Expand Up @@ -136,7 +135,7 @@ export const CandidateDataForm: React.FC<{
}
}, [electionEvent?.presentation?.language_conf, election?.presentation?.language_conf])

const [updateImage] = useUpdate<Sequent_Backend_Candidate>()
const [updateImage, {isPending: isDeletingImage}] = useUpdate<Sequent_Backend_Candidate>()

const parseValues = useCallback(
(incoming: Sequent_Backend_Candidate_Extended): Sequent_Backend_Candidate_Extended => {
Expand Down Expand Up @@ -294,24 +293,25 @@ export const CandidateDataForm: React.FC<{
}
}

const removeImage = () => {
const removeImage = async (e: React.MouseEvent<HTMLButtonElement>) => {
e.stopPropagation()
try {
setEnabledDeleteImage(false)
let presentation = removeUrlFromPresentation(record)
updateImage("sequent_backend_candidate", {
id: record.id,
data: {
image_document_id: null,
presentation: presentation,
const presentation = removeUrlFromPresentation(record)
await updateImage(
"sequent_backend_candidate",
{
id: record.id,
data: {
image_document_id: null,
presentation: presentation,
},
},
})

setEnabledDeleteImage(true)
{returnPromise: true}
)
refresh()
} catch (e) {
console.log("error :>> ", e)
} catch (err) {
console.log("error :>> ", err)
notify(t("electionScreen.error.fileError"), {type: "error"})
setEnabledDeleteImage(true)
}
}

Expand Down Expand Up @@ -347,11 +347,12 @@ export const CandidateDataForm: React.FC<{
}

const DeleteImage: React.FC = () => (
<StyledIconButton onClick={removeImage} disabled={!enabledDeleteImage}>
{!enabledDeleteImage ? (
<CircularProgress size="18px" style={{marginRight: "6px"}} />
) : null}
<Icon variant="info" icon={faTrash as any} fontSize="18px" />
<StyledIconButton onClick={(e) => void removeImage(e)} disabled={isDeletingImage}>
{isDeletingImage ? (
<CircularProgress size={18} />
) : (
<Icon variant="info" icon={faTrash as any} fontSize="18px" />
)}
</StyledIconButton>
)

Expand Down
Loading