fixed classnames

This commit is contained in:
subnub
2024-06-23 19:20:43 -04:00
parent a425e5be6d
commit 5bf8ebd480
19 changed files with 1407 additions and 1213 deletions
+391 -301
View File
@@ -1,12 +1,16 @@
import React from "react";
import {connect} from "react-redux"
import { connect } from "react-redux";
import { editFile } from "../../actions/files";
import axios from "../../axiosInterceptor"
import axios from "../../axiosInterceptor";
import env from "../../enviroment/envFrontEnd";
import capitalize from "../../utils/capitalize";
import bytes from "bytes";
import copy from "copy-text-to-clipboard";
import { setShareSelected, editSelectedItem, editShareSelected } from "../../actions/selectedItem";
import {
setShareSelected,
editSelectedItem,
editShareSelected,
} from "../../actions/selectedItem";
import SpinnerImage from "../SpinnerImage";
import SpinnerPage from "../SpinnerPage";
import Swal from "sweetalert2";
@@ -17,34 +21,38 @@ class ShareModelContainer extends React.Component {
constructor(props) {
super(props);
this.state= {
shareableLink: "Fetching Link...",
loaded: false,
sendTo: "",
emailSent: false,
copySelected: false,
public: false,
shared: false,
}
this.state = {
shareableLink: "Fetching Link...",
loaded: false,
sendTo: "",
emailSent: false,
copySelected: false,
public: false,
shared: false,
};
this.lastLoadedID = ''
this.lastLoadedID = "";
}
componentDidMount = () => {
const id = this.props.shareSelected._id;
//`/file-service/info/${id}`
const url = this.props.shareSelected.metadata.drive ? `/file-service-google/info/${id}` : `/file-service/info/${id}`;
axios.get(url).then((response) => {
const url = this.props.shareSelected.metadata.drive
? `/file-service-google/info/${id}`
: `/file-service/info/${id}`;
axios
.get(url)
.then((response) => {
console.log("file info response", response.data);
const linkType = response.data.metadata.linkType;
const shareURL = this.props.shareSelected.metadata.drive ? response.data.metadata.link : `${currentURL}/download-page/${this.props.shareSelected._id}/${this.props.shareSelected.metadata.link}`
const shareURL = this.props.shareSelected.metadata.drive
? response.data.metadata.link
: `${currentURL}/download-page/${this.props.shareSelected._id}/${this.props.shareSelected.metadata.link}`;
console.log("share link type", linkType, response.data);
@@ -52,28 +60,21 @@ class ShareModelContainer extends React.Component {
...this.state,
shared: linkType ? true : false,
loaded: true,
shareableLink: shareURL
}))
}).catch((e) => {
console.log("Cannot get share file data", e);
})
}
shareableLink: shareURL,
}));
})
.catch((e) => {
console.log("Cannot get share file data", e);
});
};
componentDidUpdate = () => {
// console.log("share model updated");
// if (this.lastLoadedID !== this.props.shareSelected._id && this.props.shareSelected !== "") {
// if (this.props.shareSelected.metadata.link && !this.props.shareSelected.metadata.drive) {
// console.log("link already exists");
// this.lastLoadedID = this.props.shareSelected._id;
// const shareURL = this.props.shareSelected.metadata.drive ? results.data : `${currentURL}/download-page/${this.props.shareSelected._id}/${this.props.shareSelected.metadata.link}`
// return this.setState(() => {
// return {
// ...this.state,
@@ -83,27 +84,18 @@ class ShareModelContainer extends React.Component {
// }
// })
// }
// this.lastLoadedID = this.props.shareSelected._id;
// console.log("share props", this.props.shareSelected)
// const url = this.props.shareSelected.metadata.drive ? currentURL +`/file-service-google/make-public/${this.props.shareSelected._id}` : currentURL +`/file-service/make-public/${this.props.shareSelected._id}`;
// console.log("share", url)
// axios.patch(url, undefined).then((results) => {
// this.props.shareSelected.metadata.link = results.data;
// this.props.dispatch(editFile(this.props.shareSelected._id,{"metadata": {
// ...this.props.shareSelected.metadata,
// link: results.data,
// linkType: "public"
// }}));
// const shareURL = this.props.shareSelected.metadata.drive ? results.data : `${currentURL}/download-page/${this.props.shareSelected._id}/${this.props.shareSelected.metadata.link}`
// this.setState(() => {
// return {
// ...this.state,
@@ -113,73 +105,67 @@ class ShareModelContainer extends React.Component {
// }
// })
// })
// }
}
};
sendEmail = (e) => {
e.preventDefault()
e.preventDefault();
if (this.state.sendTo.length === 0 || !this.state.loaded) return;
if (!this.state.shared) {
Swal.fire({
icon: 'error',
title: 'You must share the file first',
text: 'Select make public or make one time before sending email',
})
icon: "error",
title: "You must share the file first",
text: "Select make public or make one time before sending email",
});
return;
}
console.log("sending email share request")
console.log("sending email share request");
const data = {
file: {
_id: this.props.shareSelected._id,
resp: this.state.sendTo
}
}
axios.post("/file-service/send-share-email", data).then((response) => {
file: {
_id: this.props.shareSelected._id,
resp: this.state.sendTo,
},
};
axios
.post("/file-service/send-share-email", data)
.then((response) => {
console.log("sent email share");
this.setState(() => {
return {
...this.state,
emailSent: true
}
})
}).catch((err) => {
console.log("share file email failed", err)
return {
...this.state,
emailSent: true,
};
});
})
.catch((err) => {
console.log("share file email failed", err);
Swal.fire({
icon: 'error',
title: 'Cannot send share email',
text: 'An error occurred when sending share email',
})
})
}
icon: "error",
title: "Cannot send share email",
text: "An error occurred when sending share email",
});
});
};
onChangeEmail = (e) => {
const value = e.target.value;
this.setState(() => {
return {
...this.state,
sendTo: value
}
})
}
return {
...this.state,
sendTo: value,
};
});
};
closeShareModel = () => {
this.props.dispatch(setShareSelected(""))
this.props.dispatch(setShareSelected(""));
this.setState(() => {
return {
shareableLink: "Fetching Link...",
@@ -187,269 +173,334 @@ class ShareModelContainer extends React.Component {
sendTo: "",
emailSent: false,
copySelected: false,
public: false
}
})
this.lastLoadedID = ''
}
public: false,
};
});
this.lastLoadedID = "";
};
copyClick = () => {
if (!this.state.loaded) return;
copy(this.state.shareableLink)
copy(this.state.shareableLink);
console.log("link copied")
console.log("link copied");
this.setState(() => {
this.setState(
() => {
return {
...this.state,
copySelected: true
}
}, () => {
console.log("new state set")
...this.state,
copySelected: true,
};
},
() => {
console.log("new state set");
window.setTimeout(() => {
this.setState(() => {
this.setState(() => {
return {
...this.state,
copySelected: false,
};
});
}, 750);
}
);
};
return {
...this.state,
copySelected: false
}
})
}, 750)
})
}
removePublicLink = async () => {
const url = this.props.shareSelected.metadata.drive
? `/file-service-google/remove-link/${this.props.shareSelected._id}`
: `/file-service/remove-link/${this.props.shareSelected._id}`;
removePublicLink = async() => {
const url = this.props.shareSelected.metadata.drive ? `/file-service-google/remove-link/${this.props.shareSelected._id}` : `/file-service/remove-link/${this.props.shareSelected._id}`
axios
.delete(url, {})
.then(() => {
this.props.dispatch(
editFile(this.props.shareSelected._id, {
metadata: {
...this.props.shareSelected.metadata,
link: undefined,
linkType: undefined,
},
})
);
axios.delete(url, {
}).then(() => {
this.props.dispatch(
editSelectedItem({ link: undefined, linkType: undefined })
);
this.props.dispatch(editFile(this.props.shareSelected._id,{"metadata": {
...this.props.shareSelected.metadata,
link: undefined,
linkType: undefined
}}))
this.props.dispatch(editSelectedItem({link: undefined,
linkType: undefined}))
this.props.dispatch(editShareSelected({"metadata": {
...this.props.shareSelected.metadata,
link: undefined,
linkType: undefined
}}))
this.props.dispatch(
editShareSelected({
metadata: {
...this.props.shareSelected.metadata,
link: undefined,
linkType: undefined,
},
})
);
this.setState(() => ({
...this.state,
shared: false,
}))
}));
//this.closeShareModel();
}).catch((err) => {
console.log(err)
})
.catch((err) => {
console.log(err);
Swal.fire({
icon: 'error',
title: 'Cannot remove public link',
text: 'An error occurred when removing public link',
})
})
}
icon: "error",
title: "Cannot remove public link",
text: "An error occurred when removing public link",
});
});
};
makePublic = () => {
this.showingSwal = true;
Swal.fire({
title: 'Are you sure?',
text: "Making this public, will allow anyone to have access to it",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, make public'
}).then((result) => {
title: "Are you sure?",
text: "Making this public, will allow anyone to have access to it",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: "Yes, make public",
}).then((result) => {
this.showingSwal = false;
this.showingSwal = false;
if (result.value) {
if (result.value) {
const url = this.props.shareSelected.metadata.drive
? `/file-service-google/make-public/${this.props.shareSelected._id}`
: `/file-service/make-public/${this.props.shareSelected._id}`;
const url = this.props.shareSelected.metadata.drive ? `/file-service-google/make-public/${this.props.shareSelected._id}` : `/file-service/make-public/${this.props.shareSelected._id}`;
axios.patch(url, undefined).then((results) => {
this.props.dispatch(editFile(this.props.shareSelected._id,{"metadata": {
...this.props.shareSelected.metadata,
link: results.data,
linkType: "public"
}}))
axios
.patch(url, undefined)
.then((results) => {
this.props.dispatch(
editFile(this.props.shareSelected._id, {
metadata: {
...this.props.shareSelected.metadata,
link: results.data,
linkType: "public",
},
})
);
this.props.dispatch(editSelectedItem({link: results.data,
linkType: "public"}))
this.props.dispatch(
editSelectedItem({ link: results.data, linkType: "public" })
);
this.props.dispatch(editShareSelected({"metadata": {
...this.props.shareSelected.metadata,
link: results.data,
linkType: "public"
}}))
this.props.dispatch(
editShareSelected({
metadata: {
...this.props.shareSelected.metadata,
link: results.data,
linkType: "public",
},
})
);
const shareURL = this.props.shareSelected.metadata.drive ? results.data : `${currentURL}/download-page/${this.props.shareSelected._id}/${results.data}`
const shareURL = this.props.shareSelected.metadata.drive
? results.data
: `${currentURL}/download-page/${this.props.shareSelected._id}/${results.data}`;
this.setState(() => ({
...this.state,
shared: true,
shareableLink: shareURL
}))
}).catch((err) => {
console.log(err)
Swal.fire({
icon: 'error',
title: 'Cannot make public',
text: 'An error occurred when making file public'
})
})
}
})
}
this.setState(() => ({
...this.state,
shared: true,
shareableLink: shareURL,
}));
})
.catch((err) => {
console.log(err);
Swal.fire({
icon: "error",
title: "Cannot make public",
text: "An error occurred when making file public",
});
});
}
});
};
makeOne = () => {
this.showingSwal = true;
this.showingSwal = true;
Swal.fire({
title: "Are you sure?",
text: "One time link, will allow anyone to access this file once",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: "Yes, create link",
}).then((result) => {
this.showingSwal = false;
Swal.fire({
title: 'Are you sure?',
text: "One time link, will allow anyone to access this file once",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, create link'
}).then((result) => {
this.showingSwal = false;
if (result.value) {
axios.patch(`/file-service/make-one/${this.props.shareSelected._id}`, undefined).then((results) => {
this.props.dispatch(editFile(this.props.shareSelected._id,{"metadata": {
...this.props.shareSelected.metadata,
link: results.data,
linkType: "one"
}}))
this.props.dispatch(editSelectedItem({link: results.data,
linkType: "one"}))
this.props.dispatch(editShareSelected({"metadata": {
...this.props.shareSelected.metadata,
link: results.data,
linkType: "one"
}}))
this.setState(() => ({
...this.state,
shared: true,
}))
const shareURL = this.props.shareSelected.metadata.drive ? results.data : `${currentURL}/download-page/${this.props.shareSelected._id}/${results.data}`
this.setState(() => ({
...this.state,
shared: true,
shareableLink: shareURL
}))
}).catch((err) => {
console.log(err)
Swal.fire({
icon: 'error',
title: 'Cannot make one time public link',
text: 'An error occurred when making one time public link',
})
if (result.value) {
axios
.patch(
`/file-service/make-one/${this.props.shareSelected._id}`,
undefined
)
.then((results) => {
this.props.dispatch(
editFile(this.props.shareSelected._id, {
metadata: {
...this.props.shareSelected.metadata,
link: results.data,
linkType: "one",
},
})
);
}
})
this.props.dispatch(
editSelectedItem({ link: results.data, linkType: "one" })
);
}
this.props.dispatch(
editShareSelected({
metadata: {
...this.props.shareSelected.metadata,
link: results.data,
linkType: "one",
},
})
);
this.setState(() => ({
...this.state,
shared: true,
}));
const shareURL = this.props.shareSelected.metadata.drive
? results.data
: `${currentURL}/download-page/${this.props.shareSelected._id}/${results.data}`;
this.setState(() => ({
...this.state,
shared: true,
shareableLink: shareURL,
}));
})
.catch((err) => {
console.log(err);
Swal.fire({
icon: "error",
title: "Cannot make one time public link",
text: "An error occurred when making one time public link",
});
});
}
});
};
removeLink = () => {
const url = this.props.shareSelected.metadata.drive
? `/file-service-google/remove-link/${this.props.shareSelected._id}`
: `/file-service/remove-link/${this.props.shareSelected._id}`;
const url = this.props.shareSelected.metadata.drive ? `/file-service-google/remove-link/${this.props.shareSelected._id}` : `/file-service/remove-link/${this.props.shareSelected._id}`
axios
.delete(url, {})
.then(() => {
this.props.dispatch(
editFile(this.props.shareSelected._id, {
metadata: {
...this.props.shareSelected.metadata,
link: undefined,
linkType: undefined,
},
})
);
axios.delete(url, {
}).then(() => {
this.props.dispatch(
editSelectedItem({ link: undefined, linkType: undefined })
);
this.props.dispatch(editFile(this.props.shareSelected._id,{"metadata": {
...this.props.shareSelected.metadata,
link: undefined,
linkType: undefined
}}))
this.props.dispatch(editSelectedItem({link: undefined,
linkType: undefined}))
this.props.dispatch(editShareSelected({"metadata": {
...this.props.shareSelected.metadata,
link: undefined,
linkType: undefined
}}))
}).catch((err) => {
console.log(err)
this.props.dispatch(
editShareSelected({
metadata: {
...this.props.shareSelected.metadata,
link: undefined,
linkType: undefined,
},
})
);
})
.catch((err) => {
console.log(err);
Swal.fire({
icon: 'error',
title: 'Cannot remove public link',
text: 'An error occurred when removing public link',
})
})
}
icon: "error",
title: "Cannot remove public link",
text: "An error occurred when removing public link",
});
});
};
render() {
return (
<div class="modal__wrap" style={this.props.shareSelected !== "" ? {display:"block"} : {display:"none"}}>
<div class="inner__modal">
<div class="share__modal">
<div class="share__head">
<div class="share__type">
<div
className="modal__wrap"
style={
this.props.shareSelected !== ""
? { display: "block" }
: { display: "none" }
}
>
<div className="inner__modal">
<div className="share__modal">
<div className="share__head">
<div className="share__type">
<img src="/assets/extension1.svg" alt="extension" />
</div>
<div class="share__info">
<p>{this.props.shareSelected !== "" ? capitalize(this.props.shareSelected.filename) : ""}</p>
<span>{this.props.shareSelected !== "" ? bytes(this.props.shareSelected.length) : 0}</span>
<div className="share__info">
<p>
{this.props.shareSelected !== ""
? capitalize(this.props.shareSelected.filename)
: ""}
</p>
<span>
{this.props.shareSelected !== ""
? bytes(this.props.shareSelected.length)
: 0}
</span>
</div>
<div class="close__modal">
<div className="close__modal">
<a>
<img src="/assets/close.svg" alt="close" onClick={this.closeShareModel}/>
<img
src="/assets/close.svg"
alt="close"
onClick={this.closeShareModel}
/>
</a>
</div>
</div>
<div class="share__recipient">
<div className="share__recipient">
<p>Send to:</p>
<form onSubmit={this.sendEmail}>
<div class="group__input float__span">
<input onChange={this.onChangeEmail} value={this.state.sendTo} type="text" placeholder="Email Address"/>
<div className="group__input float__span">
<input
onChange={this.onChangeEmail}
value={this.state.sendTo}
type="text"
placeholder="Email Address"
/>
{/* <span>Email address</span> */}
</div>
<div class="group__submit">
<div className="group__submit">
<input type="submit" value="Send" />
</div>
</form>
<div class="share__success" style={this.state.emailSent ? {display:"block"} : {display:"none"}}>
<div
className="share__success"
style={
this.state.emailSent
? { display: "block" }
: { display: "none" }
}
>
<p>
<span>
<img src="/assets/success.svg" alt="success" />
@@ -458,37 +509,76 @@ class ShareModelContainer extends React.Component {
</p>
</div>
</div>
<div className="share-model-spinner-wrapper" style={!this.state.loaded ? {} : {display: "none"}}>
<div
className="share-model-spinner-wrapper"
style={!this.state.loaded ? {} : { display: "none" }}
>
<SpinnerPage />
</div>
<div className="share-model-share-buttons-wrapper" style={!this.state.shared && this.state.loaded ? {} : {display:"none"}}>
<div
className="share-model-share-buttons-wrapper"
style={
!this.state.shared && this.state.loaded
? {}
: { display: "none" }
}
>
<div className="share-button__wrapper">
<button onClick={this.makePublic} className="button popup-window__button">Make Public</button>
<button
onClick={this.makePublic}
className="button popup-window__button"
>
Make Public
</button>
</div>
<div className="share-button__wrapper">
<button onClick={this.makeOne} style={this.props.shareSelected.metadata.drive ? {display: "none"} : {}} className="button popup-window__button">Make One Time Link</button>
<button
onClick={this.makeOne}
style={
this.props.shareSelected.metadata.drive
? { display: "none" }
: {}
}
className="button popup-window__button"
>
Make One Time Link
</button>
</div>
</div>
<div class="get__share--link" style={this.state.shared ? {} : {display: "none"}}>
<div
className="get__share--link"
style={this.state.shared ? {} : { display: "none" }}
>
<p>File link:</p>
<div class="get__link">
<div class="copied__wrap" style={this.state.copySelected ? {display: "block"} : {display:"none"}}>
<div className="get__link">
<div
className="copied__wrap"
style={
this.state.copySelected
? { display: "block" }
: { display: "none" }
}
>
<p>
<img src="/assets/copiedcheck.svg" alt="check" /> Copied
</p>
</div>
<input
type="text"
value={this.state.shareableLink}
readonly
/>
<input type="text" value={this.state.shareableLink} readonly />
<a onClick={this.copyClick}>
<img src="/assets/copy.svg" alt="copy" />
</a>
</div>
</div>
<div className="share-button__wrapper" style={this.state.shared ? {} : {display:"none"}}>
<button onClick={this.removePublicLink} className="button popup-window__button">Remove Public Access</button>
<div
className="share-button__wrapper"
style={this.state.shared ? {} : { display: "none" }}
>
<button
onClick={this.removePublicLink}
className="button popup-window__button"
>
Remove Public Access
</button>
</div>
</div>
</div>
@@ -498,7 +588,7 @@ class ShareModelContainer extends React.Component {
}
const connectStoreToProp = (state) => ({
shareSelected: state.selectedItem.shareSelected
})
shareSelected: state.selectedItem.shareSelected,
});
export default connect(connectStoreToProp)(ShareModelContainer);