--- /dev/null
+import axios from 'axios';
+import React, { useEffect, useState } from 'react';
+import { useParams } from 'react-router-dom';
+
+import ErrorBoundary from '../common/ErrorBoundary';
+import ErrorMessage from '../common/ErrorMessage';
+import Loading from '../common/Loading';
+import NotFound from '../pages/NotFound';
+import Profile from '../users/Profile';
+
+const User = () => {
+ const params = useParams();
+ const { id } = params;
+
+ const [error, setError] = useState(null);
+ const [loading, setLoading] = useState(true);
+ const [user, setUser] = useState(null);
+
+ useEffect(() => {
+ setLoading(true);
+ axios
+ .get(`/api/users/${id}`)
+ .then(response => {
+ setError(null);
+ setLoading(false);
+ setUser(response.data);
+ })
+ .catch(error => {
+ setError(error);
+ setLoading(false);
+ setUser(null);
+ });
+ }, [id]);
+
+ useEffect(() => {
+ const cb = (e) => {
+ if (e.user) {
+ setUser(user => e.user.id === user.id ? { ...user, ...e.user } : user);
+ }
+ };
+ window.Echo.channel('App.Control')
+ .listen('UserChanged', cb);
+ return () => {
+ window.Echo.channel('App.Control')
+ .stopListening('UserChanged', cb);
+ };
+ }, []);
+
+ if (loading) {
+ return <Loading />;
+ }
+
+ if (error) {
+ return <ErrorMessage error={error} />;
+ }
+
+ if (!user) {
+ return <NotFound />;
+ }
+
+ return <ErrorBoundary>
+ <Profile user={user} />
+ </ErrorBoundary>;
+};
+
+export default User;