2023-01-05 09:06:39 +00:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2022-12-29 11:48:24 +00:00
|
|
|
import { appVersionService } from '@/_services';
|
|
|
|
|
import AlertDialog from '@/_ui/AlertDialog';
|
|
|
|
|
import { toast } from 'react-hot-toast';
|
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
|
|
|
|
|
export const EditVersion = ({
|
|
|
|
|
appId,
|
|
|
|
|
value: editingVersionId,
|
|
|
|
|
setAppVersions,
|
|
|
|
|
setShowEditAppVersion,
|
|
|
|
|
showEditAppVersion,
|
2023-01-05 09:06:39 +00:00
|
|
|
editingVersion,
|
2022-12-29 11:48:24 +00:00
|
|
|
}) => {
|
|
|
|
|
const [isEditingVersion, setIsEditingVersion] = useState(false);
|
2023-01-05 09:06:39 +00:00
|
|
|
const [versionName, setVersionName] = useState(editingVersion?.name || '');
|
2022-12-29 11:48:24 +00:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
|
|
const editVersion = () => {
|
|
|
|
|
if (versionName.trim() === '') {
|
2023-01-04 07:58:55 +00:00
|
|
|
toast.error('Version name should not be empty');
|
2022-12-29 11:48:24 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setIsEditingVersion(true);
|
|
|
|
|
appVersionService
|
|
|
|
|
.save(appId, editingVersionId, { name: versionName })
|
|
|
|
|
.then(() => {
|
|
|
|
|
toast.success('Version name updated');
|
|
|
|
|
appVersionService.getAll(appId).then((data) => {
|
|
|
|
|
const versions = data.versions;
|
|
|
|
|
setAppVersions(versions);
|
|
|
|
|
});
|
|
|
|
|
setIsEditingVersion(false);
|
|
|
|
|
setShowEditAppVersion(false);
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
setIsEditingVersion(false);
|
|
|
|
|
toast.error(error?.error);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<AlertDialog
|
|
|
|
|
show={showEditAppVersion}
|
2023-01-03 03:01:47 +00:00
|
|
|
closeModal={() => setShowEditAppVersion(false)}
|
2022-12-29 11:48:24 +00:00
|
|
|
title={t('editor.appVersionManager.editVersion', 'Edit Version')}
|
|
|
|
|
>
|
2023-01-05 09:06:39 +00:00
|
|
|
<form
|
|
|
|
|
onSubmit={(e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
editVersion();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div className="row mb-3">
|
|
|
|
|
<div className="col modal-main">
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
onChange={(e) => setVersionName(e.target.value)}
|
|
|
|
|
className="form-control"
|
|
|
|
|
placeholder={t('editor.appVersionManager.enterVersionName', 'Enter version name')}
|
|
|
|
|
disabled={isEditingVersion}
|
|
|
|
|
value={versionName}
|
|
|
|
|
maxLength={25}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2022-12-29 11:48:24 +00:00
|
|
|
</div>
|
2023-01-05 09:06:39 +00:00
|
|
|
<div className="row">
|
|
|
|
|
<div className="col d-flex justify-content-end">
|
|
|
|
|
<button className="btn mx-2" onClick={() => setShowEditAppVersion(false)} type="button">
|
|
|
|
|
{t('globals.cancel', 'Cancel')}
|
|
|
|
|
</button>
|
|
|
|
|
<button className={`btn btn-primary ${isEditingVersion ? 'btn-loading' : ''}`} type="submit">
|
|
|
|
|
{t('globals.save', 'Save')}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2022-12-29 11:48:24 +00:00
|
|
|
</div>
|
2023-01-05 09:06:39 +00:00
|
|
|
</form>
|
2022-12-29 11:48:24 +00:00
|
|
|
</AlertDialog>
|
|
|
|
|
);
|
|
|
|
|
};
|